[python-win32] Keeping a Tkinter window above all other

Bertrand Bine bbine at freesurf.fr
Mon May 22 18:54:22 CEST 2006


Metz, Bobby W, WWCS a écrit :

>Bertrand,
>	This is somewhat easy to google for, but you come up with many
>hints and pieces of the puzzle.  At least when I searched for this
>awhile back there was no one answer that held all the pieces to the
>puzzle.  So, below is what I learned along between google and just
>trial/error.
>	There's two ways to do it.  Note, the redrawing of the window
>may not do exactly what you expect...it is tkinter after all.  Just
>replace <toplevel> below with the name of your toplevel window.
>
>Tkinter way
>------------------------
><toplevel>.wm_attributes("-topmost", 1)   # Make sure window remains on
>top of all others
><toplevel>.focus()                        # Set focus to window
>
>win32com way
>------------------------
>import win32ui, win32con, win32gui
>hwnd = int(eval(<toplevel>.wm_frame()))	# Get the window info from the
>window manager
>win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0,
>win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
>
>	Some things to note if your "topmost" window will be a child
>window of another Tkinter window.  If you open a child window and set it
>as "topmost", e.g. the IE or Firefox Help-->About windows, then minimize
>the entire application to the taskbar, the methods below won't force the
>child window  above the parent window on restoral from minimization if
>you select the main window icon in the Windows taskbar.  I work around
>this by disabling the parent window so it's still visible but it ignores
>user clicks.
>
><toplevel_parent>.wm_attributes("-disabled", 1)     # Disable parent so
>user has to use child
>
>	I also never could figure out how to get the Windows taskbar to
>not show an icon for the "topmost" child window.  The transient() call
>was supposed to do this I thought but in practice it doesn't work for
>me.  Perhaps someone else on the list knows the answer.
>
><toplevel>.transient()                              # Make it a
>transient of the parent
>
>If you're making your primary app window "topmost" then these concerns
>are moot but thought I'd mention them.  
>
>Bobby
>
>-----Original Message-----
>From: python-win32-bounces at python.org
>[mailto:python-win32-bounces at python.org]On Behalf Of Bertrand Bine
>Sent: Sunday, May 14, 2006 10:27 AM
>To: python-win32 at python.org
>Subject: [python-win32] Keeping a Tkinter window above all other
>
>
>Could someone tell me how to keep a Tkinter windows above all others
>(under Windows) ?
>
>Being able to intercept the unvisibility of Tk windows when it occurs
>would certainly be usefull...
>
>Thanks for your help
>
>Bertrand.
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32 at python.org
>http://mail.python.org/mailman/listinfo/python-win32
>
>  
>
Thanks, that is exactly what I looked for.

It works fine.




More information about the Python-win32 mailing list