[py3] Tkinter menu checkbutton not working

2010-06-09 Thread Dodo

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
--
http://mail.python.org/mailman/listinfo/python-list


Re: [py3] Tkinter menu checkbutton not working

2010-06-09 Thread Terry Reedy

On 6/9/2010 12:26 PM, Dodo wrote:

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?


You never change it ;-)
Passing the *value* 0 to the widget has no effect on the binding of 
self.ck. You need to pass a container whose contents the widget can 
modify == specifically an IntVar. See 24.1.6.4. Coupling Widget Variables.


Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list