How to put a Toplevel window in front of the main window in Tkinter?


The Tkinter Toplevel window creates an additional window apart from the main window. We can add widgets and components to the newly created top-level window. It supports all the properties of the parent or main window.

Sometimes the Toplevel window is also referred to as the child window. To put the child window in front of the parent window, we can use the wm_transient() method.

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")
win.title("Parent Window")

# Create a Toplevel window
top=Toplevel(win)
top.geometry('600x250')
top.title("Child Window")

# Place the toplevel window at the top
top.wm_transient(win)

win.mainloop()

Output

If we run the above code, it will display a Toplevel window in front of the main window.

Updated on: 05-Aug-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements