472,958 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Tkinter: modal ok in windows, but not in Linux

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 a
button labeled "ok". The second window is supposed to be modal - it should
not be possible to reset the focus back to the first window or close the
first window without first closing the second. The program works just fine
in Windows XP home, but in Linux I can close the first window while the
second one is still active.

This seems to be a bug, or am I doing something wrong. I searched google
for Tkinter Linux modal, but found nothing relevant.

Thanks for your help.

Here's the code, copied and pasted from IDLE.

#############################
from Tkinter import *

makemodal = 1

def dialog():
win = Toplevel()
Label(win, text = "Secondary").pack()
Button(win, text = "Ok", command = win.destroy).pack()
if makemodal:
win.focus_set()
win.grab_set()
win.wait_window()
print "dialog exit"

root = Tk()
Button(root, text = 'popup', command = dialog).pack()
root.mainloop()
#################################

Mike
mmoum-xxxspam.woh.rr.com
--
Remove -xxxspam to reply

Jul 18 '05 #1
3 3246
DoubleM <mm***@woh.rr.com> wrote in message news:<NW****************@fe2.columbus.rr.com>...
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 a
button labeled "ok". The second window is supposed to be modal - it should
not be possible to reset the focus back to the first window or close the
first window without first closing the second. The program works just fine
in Windows XP home, but in Linux I can close the first window while the
second one is still active.

This seems to be a bug, or am I doing something wrong. I searched google
for Tkinter Linux modal, but found nothing relevant.

Thanks for your help.

Here's the code, copied and pasted from IDLE.

#############################
from Tkinter import *

makemodal = 1

def dialog():
win = Toplevel()
Label(win, text = "Secondary").pack()
Button(win, text = "Ok", command = win.destroy).pack()
if makemodal:
win.focus_set()
win.grab_set()
win.wait_window()
print "dialog exit"

root = Tk()
Button(root, text = 'popup', command = dialog).pack()
root.mainloop()
#################################

Mike
mmoum-xxxspam.woh.rr.com


Hi Mike,

I guess you should use

root.wait_window(win)

instead of

win.wait_window()

Cheers

Michael
Jul 18 '05 #2
klappnase wrote:
DoubleM <mm***@woh.rr.com> wrote in message news:<NW****************@fe2.columbus.rr.com>...
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 a
button labeled "ok". The second window is supposed to be modal - it should
not be possible to reset the focus back to the first window or close the
first window without first closing the second. The program works just fine
in Windows XP home, but in Linux I can close the first window while the
second one is still active.

This seems to be a bug, or am I doing something wrong. I searched google
for Tkinter Linux modal, but found nothing relevant.

Thanks for your help.

Here's the code, copied and pasted from IDLE.

#############################
from Tkinter import *

makemodal = 1

def dialog():
win = Toplevel()
Label(win, text = "Secondary").pack()
Button(win, text = "Ok", command = win.destroy).pack()
if makemodal:
win.focus_set()
win.grab_set()
win.wait_window()
print "dialog exit"

root = Tk()
Button(root, text = 'popup', command = dialog).pack()
root.mainloop()
#################################

Mike
mmoum-xxxspam.woh.rr.com

Hi Mike,

I guess you should use

root.wait_window(win)

instead of

win.wait_window()


It is indeed better, and so is doing a:

win.transient(root)

to avoid being able to put the main window on top of the dialog.

This won't however solve the OP's problem, which is that the main window can
still be closed when the second window is running.

We've had the same problem, and I finally ended up thinking this problem's is
not Python's fault, nor Tkinter's one, nor even tk's one: with X11, the controls
on the window frame are actually managed not by the client application (from the
X11 server point of view), but by the window manager. If the window manager
decides to ignore the grab set on one of your windows and to continue to treat
events for the other windows, you're stuck. The only thing you can do is
treating the window deletion event to explicitely ignore it via a
root.protocol('WM_DELETE_WINDOW', ...). There may be a way of doing it
automatically at tk's level, but it would certainly be a big work, not to
mention that there may be some window managers that *do* take the grab_set into
account, and so where this work would be unnecessary.

There are other issues due to the window manager on various platforms; for
example, the CDE window manager dtwm used on Sun's apparently can't make a
window always stay on top of another. So dialogs on Sun's can always be put
behind by clicking on another window of your application, which is really annoying.

All of the above is only my analysis of the problem; if anybody can confirm or
prove me wrong, I'll be happy to learn something :-). But since tk is just a
layer on "native" widgets for all platforms, you may always get behaviour
differences across platforms for such things. I suppose other toolkits using the
same principles (e.g. wxWindows) may have the same problems.

HTH
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #3
Eric Brunel wrote:

<much snipped here>
This won't however solve the OP's problem, which is that the main window
can still be closed when the second window is running.

We've had the same problem, and I finally ended up thinking this problem's
is not Python's fault, nor Tkinter's one, nor even tk's one: with X11, the
controls on the window frame are actually managed not by the client
application (from the X11 server point of view), but by the window
manager. If the window manager decides to ignore the grab set on one of
your windows and to continue to treat events for the other windows, you're
stuck. The only thing you can do is treating the window deletion event to
explicitely ignore it via a root.protocol('WM_DELETE_WINDOW', ...). There
may be a way of doing it automatically at tk's level, but it would
certainly be a big work, not to mention that there may be some window
managers that *do* take the grab_set into account, and so where this work
would be unnecessary.


Thanks for the replies. I rather suspected as much, given that it works
find in Windows XP, but was hoping I was wrong.

Mike

Jul 18 '05 #4

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

Similar topics

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...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
3
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it...
5
by: H J van Rooyen | last post by:
Hi, I am struggling to get the pack method to do what I intend. I am trying to display user input in a seperate window, along with a little description of the field, something like this: ...
4
by: peter | last post by:
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...
2
by: Mike | last post by:
Hi, I'm having a problem with modal forms on windows. I've written a very short test program, with a main window and a form called from the main window. The form is set to modal with...
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.