473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Tkinter check box behaviour - Windows / Linux discrepancy

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.

Any ideas? I am using
Linux: Fedora Core 3, Python 2.3.4
Windows: Windows NT, Python 2.3.4

Peter

================================================== ======================
import Tkinter as tk

class App:

def __init__(self,frmMain):

"""
Demonstrate difference in Windows / Linux handling of check box

Text in lblTest should track check box state
"""

# Set up form

self.intTest=tk.IntVar()

self.chkTest=tk.Checkbutton(frmMain,text='Click
me!',variable=self.intTest)

self.chkTest.grid(row=0,column=0,padx=5,pady=5,sti cky=tk.W)

self.chkTest.bind('<ButtonRelease-1>',self.chkTest_click)

self.lblTest=tk.Label(frmMain,text='Dummy')

self.lblTest.grid(row=1,column=0,padx=5,pady=5,sti cky=tk.W)
self.chkTest_click() # so as to initialise text

def chkTest_click(self,event=None):
# read check box state and display appropriate text
if self.intTest.get()==0:
self.lblTest.config(text='Check box cleared')
else:
self.lblTest.config(text='Check box set')


if __name__=='__main__':

frmMain=tk.Tk()

app=App(frmMain)

frmMain.mainloop()

Nov 9 '06 #1
4 3017
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
Nov 10 '06 #2
Peter,
You already have an answer to you question but if
you want to fancy up your program you could
replace;

self.chkTest.bind('<ButtonRelease-1>',
self.chkTest_click)
>
with
>
self.chkTest.bind('<f2>',self.chkTest_click0)

or some other acceptable key from the keyboard
>

def chkTest_click0(self,event):
self.chkTest_click()
def chkTest_click(self):
# read check box state and display
appropriate text
if self.intTest.get()==0:
self.lblTest.config(text='Check box
cleared')
else:
self.lblTest.config(text='Check box
set')

jim-on-linux
http://www.inqvista.com

On Thursday 09 November 2006 18: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.

Any ideas? I am using
Linux: Fedora Core 3, Python 2.3.4
Windows: Windows NT, Python 2.3.4

Peter

===============================================
========================= import Tkinter as tk

class App:

def __init__(self,frmMain):

"""
Demonstrate difference in Windows /
Linux handling of check box

Text in lblTest should track check box
state """

# Set up form

self.intTest=tk.IntVar()
self.chkTest=tk.Checkbutton(frmMain,text='Click
me!',variable=self.intTest)
self.chkTest.grid(row=0,column=0,padx=5,pady=5,
sticky=tk.W)
self.chkTest.bind('<ButtonRelease-1>',self.chkT
est_click)


self.lblTest=tk.Label(frmMain,text='Dummy')
self.lblTest.grid(row=1,column=0,padx=5,pady=5,
sticky=tk.W)
self.chkTest_click() # so as to
initialise text

def chkTest_click(self,event=None):
# read check box state and display
appropriate text if self.intTest.get()==0:
self.lblTest.config(text='Check box
cleared') else:
self.lblTest.config(text='Check box
set')


if __name__=='__main__':

frmMain=tk.Tk()

app=App(frmMain)

frmMain.mainloop()
Nov 10 '06 #3
Thank you for those suggestions

I've tried it on Windows and it seems fine (with the minor change to
command=self.chkTest_click). I'm currently at work, with no access to
Linux, so can't test it there until this evening.

Muchas gracias!

Nov 10 '06 #4
Thank you for those suggestions

I've tried it on Windows and it seems fine (with the minor change to
command=self.chkTest_click). I'm currently at work, with no access to
Linux, so can't test it there until this evening.

Muchas gracias!

Nov 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: wang xiaoyu | last post by:
Hello,everyone. my program runs well in windows,i use tkSimpleDialog to receive some input,but when i copy my program into Linux RH8.0,entrys in my tkSimpleDialog derived Dialog have a vital...
3
by: Rob Andrews | last post by:
I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I installed 2.3 separately into /home/rob/Python-2.3/ (creating the symbolic link "py23" to point to my 2.3 installation). Now I'm...
3
by: anuradha.k.r | last post by:
hi, Have a problem in python installation.I have already installed python 2.2 in my linux machine,but i guess tkinter packages were not selected then.Now i want to use tkinter as an interface for...
3
by: DoubleM | last post by:
Hi, I'm running Python2.3.3c1 on Mandrake 9.1 The following code is designed to bring up a window with a button labeled "popup". Clicking on the popup buttons triggers a secondary window with...
4
by: Jeffrey Barish | last post by:
I'm confused about how to use the update_idletasks method. In my program, I have a handler for a button in which execution will linger. During that time, I would like for the GUI to continue to...
1
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker...
2
by: Elbert Lev | last post by:
#When I'm running this script on my windows NT4.0 box, #every time dialog box is reopened there is memory growth 384K. #Bellow is the text I sent to Stephen Ferg (author of easygui) # I have...
7
by: Justin Ezequiel | last post by:
What font is Tkinter using for displaying utf-8 characters? On my Windows XP, most of the characters with names (unicodedata.name) are displayed WYSIWYG. However, on my Mandrake (warning: Linux...
3
by: John Pote | last post by:
I have a menu bar in a top level window as follows menuBar = Menu(rootWin) menuBar.add_command( label='Quit', command=rootWin.quit) configMenu = Menu(menuBar, tearoff=0)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.