Open In App
Related Articles

Python Tkinter – Toplevel Widget

Improve Article
Save Article
Like Article

Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in Python. Tkinter uses an object-oriented approach to make GUIs.

Note: For more information, refer to Python GUI – tkinter

Toplevel widget

A Toplevel widget is used to create a window on top of all other windows. The Toplevel widget is used to provide some extra information to the user and also when our program deals with more than one application. These windows are directly organized and managed by the Window Manager and do not need to have any parent window associated with them every time.


toplevel = Toplevel(root, bg, fg, bd, height, width, font, ..)

Optional parameters  

  • root = root window(optional) 
  • bg = background colour 
  • fg = foreground colour 
  • bd = border 
  • height = height of the widget. 
  • width = width of the widget. 
  • font = Font type of the text. 
  • cursor = cursor that appears on the widget which can be an arrow, a dot etc. 

Common methods  

  • iconify turns the windows into icon. 
  • deiconify turns back the icon into window. 
  • state returns the current state of window. 
  • withdraw removes the window from the screen. 
  • title defines title for window. 
  • frame returns a window identifier which is system specific. 

Example 1:  


from tkinter import *
root = Tk()
l = Label(root, text = "This is root window")
top = Toplevel()
l2 = Label(top, text = "This is toplevel window")



Example 2: Creating Multiple toplevels over one another 


from tkinter import *
# Create the root window
# with specified size and title
root = Tk() 
root.title("Root Window"
# Create label for root window
label1 = Label(root, text = "This is the root window")
# define a function for 2nd toplevel
# window which is not associated with
# any parent window
def open_Toplevel2(): 
    # Create widget
    top2 = Toplevel()
    # define title for window
    # specify size
    # Create label
    label = Label(top2,
                  text = "This is a Toplevel2 window")
    # Create exit button.
    button = Button(top2, text = "Exit",
                    command = top2.destroy)
    # Display until closed manually.
# define a function for 1st toplevel
# which is associated with root window.
def open_Toplevel1(): 
    # Create widget
    top1 = Toplevel(root)
    # Define title for window
    # specify size
    # Create label
    label = Label(top1,
                  text = "This is a Toplevel1 window")
    # Create Exit button
    button1 = Button(top1, text = "Exit",
                     command = top1.destroy)
    # create button to open toplevel2
    button2 = Button(top1, text = "open toplevel2",
                     command = open_Toplevel2)
    # Display until closed manually
# Create button to open toplevel1
button = Button(root, text = "open toplevel1",
                command = open_Toplevel1)
# position the button = 155, y = 50)
# Display until closed manually




Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 11 Aug, 2021
Like Article
Save Article
Similar Reads
Complete Tutorials