How to bring Tkinter window in front of other windows?

TkinterPythonGUI-Programming

Tkinter window are created and executed by mainloop() function. The mainloop() function gets executed until the application is not closed by the user abruptly.

To keep the Tkinter window above all the other windows, we can use win.after(duration, function()) function in a loop. This function inside the loop gets executed and forces the main window to appear above all the other windows.

Example

# Import the required libraries
from tkinter import *
from tkinter import ttk

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

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

# Define a function to make the window above
def lift_window():
   win.lift()
   win.after(1000, lift_window)

# Add A label widget
Label(win, text="Hey Folks, Welcome to TutorialsPoint✨", font=('Aerial 18 italic')).place(x=130, y=150)

lift_window()

win.mainloop()

Output

Run the above code to display a window that will appear above all the other windows.

raja
Published on 19-Jun-2021 08:27:00
Advertisements