I have a Tkinter window that I need to stay on top of everything else - including fullscreen windows.
Things I have tried:
root.attributes('-topmost', True)
before mainloop - doesn't work
self.root.wm_attributes("-topmost", True)
inside the class - doesn't work
root.overrideredirect(True)
before mainloop - works on Linux only
root.lift()
before mainloop - doesn't work
And finally, I set root.lift()
to be called repetitively:
class TestingGUI:
def __init__(self, root):
self.root = root
self.EnsureTop()
def EnsureTop(self):
root.lift()
root.after(5000, self.EnsureTop)`
This works in the sense that it successfully raises the window over any other windows I've manually toggled to be 'always on top', using e.g. Dexpot, but crucially it doesn't work for fullscreen applications.
Specifically, I need this to be shown over games, as it's an in-game music player. I'm fine with solutions that require some command to be used repetitively to ensure the window is called to the top again.
The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .
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.
window. 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.
- GeeksforGeeks How to Create Full Screen Window in Tkinter? There are two ways to create a full screen window in tkinter using standard python library for creating GUI applications. We will set the parameter ‘-fullscreen’ of attributes () to True for setting size of our window to fullscreen and to False otherwise.
To move a window up or down of the stack, you can use the lift () and lower () methods: The following example places the root window on top of all other windows. In other words, the root window is always on top: Tkinter window displays a default icon. To change this default icon, you follow these steps: Prepare an image in the .ico format.
Set Tkinter Window Position in Python : Like above given Size setting, you can set the position using “geometry” option in TK () class. So, let’s see the syntax of position setting.
To render widgets in a Tkinter application, we generally use mainloop () function which helps to display the widgets in a window. In many cases, tkinter window displays over the other windows or programs. While switching to other programs or windows, it seems difficult to find and switch back to the Tkinter window again.
As TessellatingHeckler pointed out in the comments, it's not possible to ensure a window stays on top of another fullscreen one. I solved this by combining a looping root.lift()
and asking my users to run their applications in a borderless window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With