Forcing Tkinter window to stay on top of fullscreen in Windows 10?


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.

We can force our tkinter window to stay on Top of other window or programs by creating a function and defining win.lift() method in a loop. In the loop, it will execute win.after(2000, function()) function to ensure that the tkinter window will always stays on top of other windows.

Example

# Import the required libraries
from tkinter import *
import lorem

# Create an instance of tkinter frame or window
win=Tk()

# Set the size of the window
win.geometry("700x350")

def stay_on_top():
   win.lift()
   win.after(2000, stay_on_top)

# Add a Label widget
Label(win, text="This window will always stay on Top", font=('Aerial 14')).pack(pady=30, anchor =CENTER)

# Call function to make the window stay on top
stay_on_top()

win.mainloop()

Output

Running the above code will display a window that will automatically remain on top of all other windows.

Updated on: 18-Jun-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements