At Thursday 9/11/2006 20:28, peter wrote:
I've come across a weird difference between the behaviour of the
Tkinter checkbox in Windows and Linux. The issue became apparent in
some code I wrote to display an image in a fixed size canvas widget. If
a checkbox was set then the image should be shrunk as necessary to fit
the canvas while if cleared it should appear full size with scrollbars
if necessary.
The code worked fine under Linux (where it was developed). But under
Windows, the first click in the checkbox did nothing, then subsequent
clicks adjusted the size according to the PREVIOUS, not the current,
checkbox state.
I've isolated the problem in the code below, which shows a single
checkbox and a label to describe its state. It works ok under Linux,
but in Windows it is always one click behind.
self.chkTest=tk.Checkbutton(frmMain,text='Click
me!',variable=self.intTest)
self.chkTest.bind('<ButtonRelease-1>',self.chkTest_click)
Your code works fine in Linux just by accident. The action of button
widgets must be associated to "command"; as you see, when the mouse
button is released, the associated variable might not have been updated.
Remove that bind call, and use:
self.chkTest=tk.Checkbutton(frmMain,text='Click
me!',variable=self.intTest, command=chkTest_click)
(Should work fine on every platform - I've just tested on Windows)
The command is fired after the mouse up event, and *only* if the
previous mouse down was over the same widget. Your code doesn't work
either if the user presses SPACE to toggle the button state; using
"command" works fine in this case too.
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
--
http://mail.python.org/mailman/listinfo/python-list