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

To render widgets in a Tkinter application, we generally use the mainloop() function which helps to display the widgets in a window. In many cases, tkinter windows display behind other windows or programs. While switching to other programs or windows, it can be difficult to find and switch back to the Tkinter window again.

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

Method 1: Using lift() with Periodic Updates

This approach uses a recursive function that calls lift() every few seconds ?

# Import the required libraries
from tkinter import *

# 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=('Arial', 14)).pack(pady=30, anchor=CENTER)

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

win.mainloop()

Method 2: Using wm_attributes() (Recommended)

A more reliable approach uses the wm_attributes() method to set the topmost property ?

from tkinter import *

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

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

# Force window to stay on top
win.wm_attributes("-topmost", 1)

# Add a Label widget
Label(win, text="This window stays on Top using wm_attributes", font=('Arial', 14)).pack(pady=30, anchor=CENTER)

win.mainloop()

Method 3: Toggle Topmost Behavior

You can also create a toggle function to enable/disable the always-on-top behavior ?

from tkinter import *

win = Tk()
win.geometry("700x350")

# Variable to track topmost state
is_topmost = False

def toggle_topmost():
    global is_topmost
    is_topmost = not is_topmost
    win.wm_attributes("-topmost", is_topmost)
    button.config(text="Disable Always on Top" if is_topmost else "Enable Always on Top")

# Create toggle button
button = Button(win, text="Enable Always on Top", command=toggle_topmost, font=('Arial', 12))
button.pack(pady=20)

Label(win, text="Click button to toggle always-on-top behavior", font=('Arial', 14)).pack(pady=30)

win.mainloop()

Comparison

Method Pros Cons
lift() with timer Works on all platforms Uses system resources, can be unreliable
wm_attributes("-topmost") Reliable, system-native Platform-specific attribute names
Toggle functionality User control, flexible Requires user interaction

Conclusion

Use wm_attributes("-topmost", 1) for the most reliable always-on-top behavior. The lift() method with timers works but consumes more resources and may be less reliable on some systems.

Updated on: 2026-03-25T23:32:09+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements