Tk and focusing windows

Graham Ashton graz at
Wed Oct 24 20:22:52 CEST 2001

In article <WUtB7.1473$P4.265030 at>, "Graham Ashton"
<graz at> 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():

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...


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

from Tkinter import *


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

dialog = Tk()
dialog.resizable(0, 0)
dialog.title("A dialog")
widget = Label(dialog, text="Why is this window drawn first?")
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