Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Tkinter window jump to the front?

How do I get a Tkinter application to jump to the front? Currently, the window appears behind all my other windows and doesn't get focus.

Is there some method I should be calling?

like image 621
nathan Avatar asked Dec 12 '09 04:12

nathan


People also ask

How do I make Tkinter pop up?

Popup window in Tkinter can be created by defining the Toplevel(win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application.

What does Mainloop () do in Tkinter?

mainloop() tells Python to run the Tkinter event loop. This method listens for events, such as button clicks or keypresses, and blocks any code that comes after it from running until you close the window where you called the method.

How do I open Tkinter in the middle of the screen?

In order to place a tkinter window at the center of the screen, we can use the PlaceWindow method in which we can pass the toplevel window as an argument and add it into the center. We can also set the window to its center programmatically by defining its geometry.


1 Answers

Assuming you mean your application windows when you say "my other windows", you can use the lift() method on a Toplevel or Tk:

root.lift() 

If you want the window to stay above all other windows, use:

root.attributes("-topmost", True) 

Where root is your Toplevel or Tk. Don't forget the - infront of "topmost"!

To make it temporary, disable topmost right after:

def raise_above_all(window):     window.attributes('-topmost', 1)     window.attributes('-topmost', 0) 

Just pass in the window you want to raise as a argument, and this should work.

like image 194
D K Avatar answered Sep 23 '22 19:09

D K