[python-win32] keep tkinter window always on top

Benjamin Rutt rutt at bmi.osu.edu
Mon Aug 22 02:03:17 CEST 2005


"Mark Hammond" <mhammond at skippinet.com.au> writes:

>> Does anyone know how to keep a tkinter window always on top, despite
>> attempts to focus other windows?  Here is my failed attempt.  I've
>> tried both tkinter-only and win32-specific solutions.  For this code,
>> the window does stay in front of the dos box it's launched from if I
>> try to focus the dos box, but that's the only one it stays in front
>> of.  Thanks, Benjamin
>
> Try something like:
>
> import win32gui
> win32gui.SetWindowPos(hWnd, win32con.HWND_TOPMOST, 0,0,0,0,
> win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)

Argh, it turns out that I needed to do

    hwnd = int(eval(root.wm_frame()))

not

    hwnd = root.winfo_id()

So much for trusting the first code for "tkinter root window->window
handle" I come across on the net. :)

Thanks, it almost works now.  Just one last problem, while it is
always on top, it doesn't always have the input focus.  Any recipes
for that?  That is, I want it to steal the focus if it doesn't have
it.  Thanks,
-- 
Benjamin Rutt



More information about the Python-win32 mailing list