tags:

views:

24

answers:

1

I am making a Menu using Tkinter but i wanted to put "add_checkbutton" instead of "add_command"into the menu options but problem is "How i deselect/select a checkbox."

menu = Menu(parent)

parent.config(menu=menu)

viewMenu = Menu(menu)

menu.add_cascade(label="View", menu=viewMenu)
viewMenu.add_command(label = "Show All", command=self.showAllEntries)
viewMenu.add_command(label="Show Done", command= self.showDoneEntries)
viewMenu.add_command(label="Show Not Done", command = self.showNotDoneEntries)
+1  A: 

You need to associate a variable with the checkbutton item(s), then set the variable to cause the item to be checked or unchecked. For example:

self.showAll = tk.BooleanVar()
self.showDone = tk.BooleanVar()
self.showNotDone = tk.BooleanVar()

viewMenu.add_checkbutton(label="Show All", onvalue=True, offvalue=False, variable=self.showAll)
viewMenu.add_checkbutton(label="Show Done", onvalue=True, offvalue=False, variable=self.showDone)
viewMenu.add_checkbutton(label="Show Not Done", onvalue=1, offvalue=False, variable=self.showNotDone)

self.showAll.set(True)
Bryan Oakley
Hi there, thanks for your reply. I am getting little problem in executing this because i am getting error about tk.BooleanVar()
itsaboutcode
@itsaboutcode: probably because you are importing Tkinter in a different way. It looks like you are importing everything from Tkinter so you can probably change the code to just "BooleanVar()".
Bryan Oakley
@Bryan Oakley - Thanks man, it worked.
itsaboutcode