[py3] Tkinter menu checkbutton not working

Dodo dodo_do_not_wake_up at yahoo.Fr
Wed Jun 9 12:26:17 EDT 2010


Hello,

I trying to make this piece of code work (this is python3)

from tkinter import *
from tkinter.ttk import *

class Window:
  def __init__(self):
   self.root = Tk()

   self.menu = Menu(self.root)
   self.root['menu'] = self.menu

   self.submenu = Menu(self.menu)
   self.ck = 0
   self.submenu.add_checkbutton(label="My checkbutton", 
variable=self.ck, command=self.displayCK)
   self.menu.add_cascade(label="sub", menu=self.submenu )

  def displayCK(self):
   print( self.ck )


app = Window()
app.root.mainloop()


The self.ck will always be 0... why?

Dorian



More information about the Python-list mailing list