Tk and focusing windows
bmoyle at mvista.com
Tue Oct 30 01:53:15 CET 2001
I'm new to Tkinter, but I decided to give this a shot anyway (using your example as the base).
It seems to do the trick, but I'm not sure if it's considered good Tkinter coding style.
from Tkinter import *
window = Toplevel()
widget = Label(window, text="I wait for the dialog, but why?")
dialog = Toplevel()
widget = Label(dialog, text="Why is this window drawn first?")
dialog.wait_visibility(window) # seems to do something!
Graham Ashton wrote:
> 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():
> 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