Reputation: 7514
Newb Question:
I'm trying to create a Tkinter GUI where the checkboxes change the values in a dictionary.
For some reason, though when I click on any one of the checkboxes all of the other checkboxes are also toggled active and inactive. What am I doing wrong?
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()
Upvotes: 0
Views: 934
Reputation: 76194
Try using Tkinter Variables instead of ordinary integers.
def __init__(self, root, **kwargs):
self.frame = root
self.frame.minsize(860, 265)
self.dic_processlist = {letter: IntVar() for letter in "abcde"}
Upvotes: 1