0

我正在为一个简单的 tkinter 问题而苦苦挣扎,我想在循环中检查检查按钮的输出。但是结果总是0。我做错了什么?

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()
4

0 回答 0