Reputation: 732
I'm struggling with a simple tkinter issue, I want to check the output from checkbuttons in a loop. But the result is always 0. What do I do wrong?
from tkinter import *
root = Tk()
files = ["amsterdam", "rotterdam", "groningen"]
rownr = 0
filesdict = dict.fromkeys(files, "")
for city in files:
rownr = rownr + 1
filesdict[city] = IntVar()
Checkbutton(root, text=city, variable=filesdict[city]).grid(row=rownr)
exitbutton = Button(root, text="exit", command=root.quit)
exitbutton.grid(row=5)
print (filesdict['amsterdam'].get())
root.mainloop()
Upvotes: 0
Views: 52