TypeError: 'NoneType' object is not subscriptable in PySimpleGUI trying to assign variables depending on the values of Combo boxes
This is for a school project and the idea is to choose options from four combo boxes and depending on what the inputs from the combo boxes are (which to my understanding value[0] would be the input from combo box 1, value[1] the input from combo box 2, etc.) I will assign a certain letter or number to the according variable (stelle_1 for value[0], stelle_2 for value[1], etc.) and when all inputs are put in and you press on 'Produkt anzeigen' you get the letters/numbers put together, which is what the programme is supposed to work like. Unfortunately I get the Type Error ''NoneType' object is not subscriptable' for the 'if values[0] == "hell":' line (if I cross that line out I get it for the next if values[1] etc.' line) and I don't really know how to fix that. I've understood that it has something to do with values being a NoneType object and not a list, but I don't understand why it's working anyway and how I would go about fixing it.
Here's my code (I don't know there's no indented block, but everything after the while repeat line should be indented) :
import PySimpleGUI as sg
sg.theme("LightBrown13")
layout = [[[sg.Text(("Hautton"), expand_x=True), sg.Text(("Unterton"), expand_x=True), sg.Text(("Hautbild"), expand_x=True), sg.Text(("Finish"), expand_x=True)],
[sg.Combo(('hell', 'mittel', 'dunkel'), readonly=True, expand_x=True),
sg.Combo(('kühl', 'neutral', 'warm'), readonly=True, expand_x=True),
sg.Combo(('normal', 'fettig', 'trocken'), readonly=True, expand_x=True),
sg.Combo(('glossy', 'matt'), readonly=True, expand_x=True)],
[sg.Button(("Produkt anzeigen"), expand_x=True, expand_y=True)]]]
window1 = sg.Window('Foundation Finder', layout, size=(1250,100), keep_on_top=True)
repeat = "Erneut durchführen"
while repeat == "Erneut durchführen":
event, values = window1.read()
if values[0] == "hell":
stelle_1 = "H"
merkmal_hautton = "hell"
elif values[0] == "mittel":
stelle_1 = "M"
merkmal_hautton = "mittel"
elif values[0] == "dunkel":
stelle_1 = "A"
merkmal_hautton = "dunkel"
else:
stelle_1 = "undefined"
merkmal_hautton = stelle_1
if values[1] == "kühl":
stelle_2 = "B"
merkmal_unterton = "kühl"
elif values[1] == "neutral":
stelle_2 = "C"
merkmal_unterton = "neutral"
elif values[1] == "warm":
stelle_2 = "D"
merkmal_unterton = "warm"
else:
stelle_2 = "undefined"
merkmal_unterton = stelle_2
if values[2] == "normal":
stelle_3 = "1"
merkmal_hautbild = "normal"
elif values[2] == "fettig":
stelle_3 = "2"
merkmal_hautbild = "fettig"
elif values[2] == "trocken":
stelle_3 = "3"
merkmal_hautbild = "trocken"
else:
stelle_3 = "undefined"
merkmal_hautbild = stelle_3
if values[3] == "glossy":
stelle_4 = "0"
merkmal_finish = "glossy"
elif values[3] == "matt":
stelle_4 = "1"
merkmal_finish = "matt"
else:
stelle_4 = "undefined"
merkmal_finish = stelle_4
produktname = stelle_1 + stelle_2 + stelle_3 + stelle_4
layout2 = [[[[sg.Text(("Ihre Angaben:"), expand_y=True)],
[sg.Text(("Hautton:"), expand_y=True), sg.Text((merkmal_hautton), expand_y=True)],
[sg.Text(("Unterton:"), expand_y=True), sg.Text((merkmal_unterton), expand_y=True)],
[sg.Text(("Hautbild:"), expand_y=True), sg.Text((merkmal_hautbild), expand_y=True)],
[sg.Text(("Finish:"), expand_y=True), sg.Text((merkmal_finish), expand_y=True)],
[sg.Text(("Wir empfehlen Ihnen basierend auf Ihren Angaben folgendes Produkt:"), expand_x=True, expand_y=True), sg.Text((produktname), expand_y=True)],
[sg.Button(("Erneut durchführen"), expand_x=True, expand_y=True), sg.Button(("Beenden"), expand_x=True, expand_y=True)]]]]
window2 = sg.Window('Empfohlenes Produkt', layout2, size=(550,260))
layout3 = [[[sg.Text(("Bitte füllen Sie alle Felder aus"), expand_x=True)],
sg.Button(("Erneut durchführen"), expand_x=True), sg.Button(("Beenden"), expand_x=True)]]
window3 = sg.Window('Fehler', layout3, size=(450,70))
if event == "Produkt anzeigen":
if stelle_1 and stelle_2 and stelle_3 and stelle_4 == "undefined":
window1.disappear()
event, values = window3.read()
else:
window1.disappear()
event, values = window2.read()
if event == "Erneut durchführen":
repeat = "Erneut durchführen"
window1.reappear()
window3.close()
window2.close()
elif event == "Beenden":
window3.close()
window2.close()
window1.close()
else:
window3.close()
window2.close()
window1.close()
from Recent Questions - Stack Overflow https://ift.tt/3HL197Q
https://ift.tt/eA8V8J
Comments
Post a Comment