jeudi 8 juillet 2021

tkinter Checkbutton not working as expected

I am trying to recreate the example as given in https://www.askpython.com/python-modules/tkinter/tkinter-checkbox-and-checkbutton, which uses the following code:

from tkinter import *

def click_me():
print(i.get())

root =Tk()
i=IntVar()
c = Checkbutton(root, text = "Python", variable=i)
c.pack()

b = Button(root,text="Click here",command=click_me)
b.pack()

root.geometry("400x400+120+120")
root.mainloop()

However, for me, it doesn't have the desired output. In the example they obtained a value of 1 for the checkbox being clicked and 0 for the checkbox being no clicked. However, I obtain a value of 0 for both when it is and is not checked. Any ideas about what I'm doing wrong been stumped for a while on this!

Versions used:

conda -- 4.10.1

tk -- 8.6.10 -- hb0a8c7a_0

spyder -- 4.2.5 -- py38hecd8cb5_0

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire