473,657 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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").pa ck()
Button(win, text = "Ok", command = win.destroy).pa ck()
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 3331
DoubleM <mm***@woh.rr.c om> wrote in message news:<NW******* *********@fe2.c olumbus.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").pa ck()
Button(win, text = "Ok", command = win.destroy).pa ck()
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_windo w(win)

instead of

win.wait_window ()

Cheers

Michael
Jul 18 '05 #2
klappnase wrote:
DoubleM <mm***@woh.rr.c om> wrote in message news:<NW******* *********@fe2.c olumbus.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").pa ck()
Button(win, text = "Ok", command = win.destroy).pa ck()
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_windo w(win)

instead of

win.wait_window ()


It is indeed better, and so is doing a:

win.transient(r oot)

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_WINDO W', ...). 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_WINDO W', ...). 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
3847
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 based on a Text widget with embedded windows and a thread running the Tkinter mainloop plus several other thread dealing with the scheduling of the contents and the acquisition of data but not using graphic widgets. I run the same code on Linux...
2
3634
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 tested the pure Tkinter, # by modifiing on of the examples in the distribution. # This little guy also exibits the same behaviour. # Namely: every time the window is closed and reoppend, # there is memory leak of several hundreds 384K
7
4362
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 newbie), most characters are displayed as \u???? where ???? is the Hex code. ## start of script Tkinter_gui.py---------- import Tkinter import ScrolledText
1
3595
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 I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
3
3602
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 yesterday), so I am sure I am overlooking something simple. The basic idea is that my application will consist of a series of modal dialogs, that are chained together in "wizard" fashion. There will be some processing in between dialogs, but for the most...
5
3528
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: Current entry Company : entered co. name First entry : entered stuff The second entry: more entered stuff
4
3042
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 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,...
2
2641
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 form.setModal(1) before calling form.show(). All works as expected on Linux. The form is modal, not allowing the main window to received the focus. If I call the form from within itself, the topmost form is modal, and not of the previous forms will...
44
4979
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 processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.