How to put a Tkinter window on top of the others?

TkinterPythonServer Side ProgrammingProgramming

Whenever we create a GUI program, tkinter generally presents the output screen in the background. In other words, tkinter displays the program window behind other programs. In order to put the tkinter window on top of others, we are required to use attributes('- topmost',True) property. It pulls up the window on the upside.

Example

#Importing the library
from tkinter import *

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

#Setting the geometry of window
win.geometry("600x350")

#Create a Label
Label(win, text= "Hello World! ",font=('Helvetica bold', 15)).pack(pady=20)

#Make the window jump above all
win.attributes('-topmost',True)

win.mainloop()

Output

Running the above code will make the window stay on top all other windows −

raja
Published on 26-Mar-2021 15:06:32
Advertisements