Why Does My Tkinter Window Background Not Change?
I've a small program with a feature to change the background color of a different window than the frame I use to ask for the background color. (I hope you understand this.) The pro
Solution 1:
The problem is this code:
c = wert.get()
if c == 1:
fenster.config(background="red")
elif c == 2:
fenster.config(background="blue")
else:
fenster.config(background="yellow")
The .get()
method is returning a str
, because you declared wert
to be a StringVar()
but you're comparing to an int
. Either convert via int(c)
or compare strings:
ifc== '1':
or perhaps declare wert
to be an IntVar()
. Also, reread how the Python global
statement works -- use it where you want to modify a global within a function, not where the global is defined.
Solution 2:
Instead of declaring wert as a StringVar, you should declare it as IntVar because in your function OptionButton you're making the comparaison between a string and an int so it always entering in the else part so your background is always yellow.
Post a Comment for "Why Does My Tkinter Window Background Not Change?"