Newb问题:
我试图创建一个Tkinter GUI,其中复选框更改字典中的值。
出于某种原因,虽然当我点击其中任何一个复选框时,所有其他复选框也会切换为活动和非活动状态。我做错了什么?
from Tkinter import *
class test(object):
def __init__(self, root, **kwargs):
self.frame = root
self.frame.minsize(860, 265)
self.dic_processlist = {'a':0, 'b':0, 'c':0, 'd':0, 'e':0}
self.chk1 = Checkbutton(text = "a", variable=self.dic_processlist['a'])
self.chk1.grid(row=6, column=1, sticky="w")
self.chk2 = Checkbutton(text = "b", variable=self.dic_processlist['b'])
self.chk2.grid(row=6, column=2, sticky="w")
self.chk3 = Checkbutton(text = "c", variable=self.dic_processlist['c'])
self.chk3.grid(row=6, column=3, sticky="w")
if __name__ == "__main__":
root = Tk()
app = test(root)
root.mainloop()
答案 0 :(得分:1)
尝试使用Tkinter Variables而不是普通的整数。
def __init__(self, root, **kwargs):
self.frame = root
self.frame.minsize(860, 265)
self.dic_processlist = {letter: IntVar() for letter in "abcde"}