Tk and focusing windows

Graham Ashton graz at mindless.com
Wed Oct 24 14:22:52 EDT 2001


In article <WUtB7.1473$P4.265030 at news1.cableinet.net>, "Graham Ashton"
<graz at mindless.com> wrote:

> I've got an application which opens two Tk windows as soon as it starts
> up; the main window and a progress dialog.
> 
> I want the dialog to be displayed after the main window (so the main
> window can't cover it up)....

Somebody suggested I have a play with wait_visibility():

  http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm

I can't get it work though. I've written a small example that
demonstrates my problem (below). It creates two top level windows, one of
which I've called a dialog, another the main window. I don't want the
dialog to be displayed on screen until after the main window has been
drawn. It looks like that is what wait_visibility() is there for, but I
think I'm using it wrong.

The only way I've managed to change the order in which the windows are
drawn is by swapping the order in which the code creates them - the
last one in the code is the first one on screen. This would be a fairly
hackish solution, and I'd have to mess around with my application's logic
to do it.

Anyway, here's the example.  Thanks...

--
Graham

---cut---
#!/usr/bin/env python
#
# How do I get the dialog to be displayed _after_ the window?

from Tkinter import *

NoDefaultRoot()

window = Tk()
window.resizable(0, 0)
window.title("Main window")
widget = Label(window, text="I wait for the dialog, but why?")
widget.pack()

dialog = Tk()
dialog.resizable(0, 0)
dialog.title("A dialog")
widget = Label(dialog, text="Why is this window drawn first?")
widget.pack()
widget.wait_visibility(window)  # does this do anything?

window.mainloop()  # same behaviour if we do dialog.mainloop()



More information about the Python-list mailing list