Tkinter buttons commands don't run
Firstly you need to define your global variable value
outside of your functions. Also sice what valueNumber()
do is just create buttons and do not call commands nb_1 and nb_2, but just assigns them as buttons commands. So returned value will be value you firstly assigned value
to, here 0
.
If you want to print value every time you changed it by clicking buttons print value inside this functions like so
from tkinter import Button, Tk, LEFTframe_output = Tk()def nb_1(): global value value=1 print(value)def nb_2(): global value value=2 print(value)def valueNumber(): global value b1=Button(frame_output, text='1', command=nb_1) b1.pack(side=LEFT) b2=Button(frame_output, text='2', command=nb_2) b2.pack(side=LEFT) x=value return xvalue = 0valueNumber()frame_output.mainloop()