Tkinter windows always on top in Win32
John Grayson
johngrayson at home.com
Tue May 9 12:14:42 EDT 2000
In article <391819ca.314642161 at news.onlineisp.com>,
remove.me.wwicker at spectratechnologies.com wrote:
> How can I set a Tkinter window to always be on top?
>
> I couldn't find this in the fine Tkinter book, nor in any of the
> examples I searched.
>
> Please help.
>
> William.
>
Good question! I didn't think of covering this in the book
because, as far as I can tell, it is not possible with Win32 and
I made an effort to show things that worked on both Win32 and Unix.
Unix is easy, since VisibilityChange events are generated. I do
not believe that Win32 generates an equivalent, except on the
initial map.
Here is a simple example for X, for anyone who is curious:
from Tkinter import *
def putOnTop(event):
event.widget.unbind('<Visibility>')
event.widget.update()
event.widget.lift()
event.widget.bind('<Visibility>', putOnTop)
root = Tk()
root.title('Always on Top')
f = Frame(root, borderwidth=2)
Label(f, text='Click MouseButton 3 to close').pack(side=LEFT)
f.pack(side=LEFT, padx=5, pady=5)
root.bind('<Visibility>', putOnTop)
root.bind('<Button-3>', lambda e, r=root : r.destroy())
root.mainloop()
If you want to be a *real* pain and keep focus on the window,
then the putOnTop function becomes:
def putOnTop(event):
event.widget.unbind('<Visibility>')
event.widget.withdraw()
event.widget.deiconify()
event.widget.update()
event.widget.lift()
event.widget.bind('<Visibility>', putOnTop)
Of course, I'm sure someone out there has had to solve
this...
John
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list