Tk and focusing windows
Brian Moyle
bmoyle at mvista.com
Mon Oct 29 19:53:15 EST 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.
Brian
-----
#!/usr/bin/env python
from Tkinter import *
import sys
root=Tk()
root.withdraw()
window = Toplevel()
window.withdraw()
window.resizable(0, 0)
window.title("Main window")
window.protocol("WM_DELETE_WINDOW", sys.exit)
widget = Label(window, text="I wait for the dialog, but why?")
widget.pack()
dialog = Toplevel()
dialog.withdraw()
dialog.resizable(0, 0)
dialog.title("A dialog")
widget = Label(dialog, text="Why is this window drawn first?")
widget.pack()
window.deiconify()
dialog.wait_visibility(window) # seems to do something!
dialog.deiconify()
root.mainloop()
-----
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():
>
> 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