Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring Tkinter window in front of other windows?

I'm working with some Tkinter Python code (Python 3.4), and I've come across a problem. When I create my Tkinter window it doesn't show up in front. I do it currently with the following code:

from tkinter import *
win = Tk()
win.minsize(width=1440, height=828)
win.maxsize(width=1440, height=828)

The minsize() and maxsize() make the window cover my entire screen, but the original python running window (The one that wouldprint("Hello, World!")) ends up on top. Is there a way to fix this? I'm running OS X 10.10.1.

like image 656
Elle Nolan Avatar asked Feb 04 '15 02:02

Elle Nolan


1 Answers

Set it as the topmost (but it will always stay in front of the others):

win.attributes('-topmost', True) # note - before topmost

To not make it always in front of the others, insert this code before the mainloop:

win.lift()
win.attributes('-topmost', True)
win.attributes('-topmost', False)

Don't forget win.mainloop() at the end of your code (even if in some cases it's not explicitly required)

Other discussions on the same problem:

  • How to put a Tkinter window on top of the others

  • How to make a Tkinter window jump to the front?

like image 196
nbro Avatar answered Oct 13 '22 09:10

nbro