Hi, I'm new to Python and tkinter programming. I have tried to find an answer to my problem on this forum, but couldn't find it. This problem is surely a most common problem, but still I am not able to solve it!
I am trying to pass on variables that contain choices made with dropdown menu's, radio buttons and so on. Every time I try this I get "0" (or "PY_VAR0" if I didn't put "choice = 0 " at the beginning of the script) as a result.
So I tried a simple script to bring things back to the essence but with the same result. My code:
What am I doing wrong?

I am trying to pass on variables that contain choices made with dropdown menu's, radio buttons and so on. Every time I try this I get "0" (or "PY_VAR0" if I didn't put "choice = 0 " at the beginning of the script) as a result.
So I tried a simple script to bring things back to the essence but with the same result. My code:
from tkinter import * master = Tk() choice = IntVar() choice = 0 def callback1(): print ("Your choice is number 1!") choice = 1 def callback2(): print ("Your choice is number 2!") choice = 2 def callback3(): print ("Your choice is number 3!") choice = 3 def callback6(): print ("Your final choice is: ") print (choice) b = Button(master, text="Choice 1", command=callback1) b.grid() b = Button(master, text="Choice 2", command=callback2) b.grid() b = Button(master, text="Choice 3", command=callback3) b.grid() b = Button(master, text="Let's show what choice you made!", command=callback6) b.grid() master.mainloop()When I make a choice: say "Choice 2", when I press the last button I expect my choice to be "2". Instead it is always "0", no matter what choice I made before.
What am I doing wrong?