5

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.

Elle Nolan
  • 379
  • 5
  • 8
  • 22
  • 2
    Possible duplicate of [How to make a window jump to the front?](http://stackoverflow.com/questions/1892339/how-to-make-a-window-jump-to-the-front) – Victor Sergienko Apr 04 '17 at 18:02
  • Calling lift() and attributes() doesn't put the window top-most in my case: * macOS 10.12.5 * Python 3.6.1 installed through Homebrew And I found this answer work in my case: * https://stackoverflow.com/a/37235492/2708288 – Alan Zhiliang Feng Jun 17 '17 at 16:30

1 Answers1

12

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:

Community
  • 1
  • 1
nbro
  • 15,395
  • 32
  • 113
  • 196