Tkinter Toplevel Example: Master Pop-Up Windows in Python

Logan Jul 13, 2026

Tkinter's toplevel widget is a powerful tool for creating independent windows in your Python GUI applications. It allows you to create new windows that can be placed over or alongside the main application window, enhancing interactivity and user experience. Let's dive into an example that demonstrates the use of Tkinter's toplevel widget.

Tabbed Interface
Tabbed Interface

In this example, we will create a simple to-do list application with a main window and a toplevel window for adding tasks. The main window will display the list of tasks, and the toplevel window will provide an interface for adding new tasks to the list.

| Pythonista Planet
| Pythonista Planet

Setting Up the Main Application Window

The main application window will be created using the Tk class from the tkinter module. This window will hold our to-do list, which is initially empty.

toefl
toefl

We will also create a function called add_task that will open the toplevel window when called. This function will be attached to a button in the main window, allowing users to open the toplevel window whenever they want to add a new task.

Creating the Main Window

an image of pixelated desserts and pastries
an image of pixelated desserts and pastries

First, let's create the main application window and display it on the screen. We'll use a simple list to store our tasks and a Label widget to display the list.

```python import tkinter as tk tasks = [] def main_window(): root = tk.Tk() root.title("To-Do List") root.geometry("300x400") list_tasks = tk.Listbox(root, width=50, height=10) list_tasks.pack(pady=10) for task in tasks: list_tasks.insert(tk.END, task) btn_add_task = tk.Button(root, text="Add Task", command=add_task) btn_add_task.pack(pady=10) root.mainloop() main_window() ```

In this code, we create a Tk instance as the main window and set its title and dimensions. Then, we create a Listbox widget to display our tasks. We loop through the tasks list and insert each task into the Listbox. Finally, we create a Button widget linked to the add_task function and pack it into the main window.

Creating the Toplevel Window for Adding Tasks

Leveling by height of instrument method of autolevel with proper diagram and example.
Leveling by height of instrument method of autolevel with proper diagram and example.

Now that we have our main window set up, let's create the toplevel window for adding new tasks to our to-do list.

The toplevel window will contain an Entry widget for users to input their task, and a Button widget to submit the task. When the task is submitted, we will add it to the tasks list and update both the main window and the toplevel window to reflect the changes.

Creating the Toplevel Window

a diagram showing how to use wireshark tcp handshake for teaching
a diagram showing how to use wireshark tcp handshake for teaching

Let's create the toplevel window and add the necessary widgets to it.

```python def add_task(): task_window = tk.Toplevel(root) task_window.title("Add Task") lbl_task = tk.Label(task_window, text="Task:") lbl_task.pack(pady=10) entry_task = tk.Entry(task_window, width=50) entry_task.pack(pady=10) def submit_task(): task = entry_task.get() tasks.append(task) list_tasks.insert(tk.END, task) task_window.destroy() btn_submit = tk.Button(task_window, text="Submit", command=submit_task) btn_submit.pack(pady=10) ```

In this code, we create a Toplevel instance as the toplevel window and set its title. We then create a Label and an Entry widget for users to input their task. We also create a Button widget linked to the submit_task function, which adds the task to the tasks list, updates the main window, and destroys the toplevel window.

Python Employee Payment System Project (Tkinter) 💰
Python Employee Payment System Project (Tkinter) 💰
an image of a computer screen with cats on it and the words, python list method
an image of a computer screen with cats on it and the words, python list method
Risk management stock illustration. Illustration of accident - 16541904
Risk management stock illustration. Illustration of accident - 16541904
an info sheet describing the different types of teeth
an info sheet describing the different types of teeth
A LEVEL Study Guide – Smart Tips for Exam Success
A LEVEL Study Guide – Smart Tips for Exam Success
Communication
Communication
a poster with different types of words and pictures on it, including the words transition words
a poster with different types of words and pictures on it, including the words transition words
a pyramid diagram showing the five levels of project management, including top level manager, bottom level
a pyramid diagram showing the five levels of project management, including top level manager, bottom level
the text next level requires a version of you, you haven't fully stepped into yet
the text next level requires a version of you, you haven't fully stepped into yet
a white piece of paper with writing on it and an image of a firewall diagram
a white piece of paper with writing on it and an image of a firewall diagram
IELTS Academic
IELTS Academic
a handwritten note on lined paper with writing in it that says, my short - term and long - term goals
a handwritten note on lined paper with writing in it that says, my short - term and long - term goals
three different angles of a futuristic vehicle with red and blue lights on the front, side, and back
three different angles of a futuristic vehicle with red and blue lights on the front, side, and back
the text is written in two different languages, and it appears to be an example
the text is written in two different languages, and it appears to be an example
how to improve writing skills for kids and adults in the classroom, with instructions on how to
how to improve writing skills for kids and adults in the classroom, with instructions on how to
a piece of paper with some writing on it
a piece of paper with some writing on it
Rounding Numbers to the Nearest 10 and 100 - Round Whole Numbers Worksheets
Rounding Numbers to the Nearest 10 and 100 - Round Whole Numbers Worksheets
Computer Network Unit 3 Cheat Sheet 🌐 | Network Layer, IP, Routing & Subnetting (AKTU)
Computer Network Unit 3 Cheat Sheet 🌐 | Network Layer, IP, Routing & Subnetting (AKTU)
Teach Your Kids to Code with Tynker
Teach Your Kids to Code with Tynker
two sheets of paper with red writing on them sitting on a table next to each other
two sheets of paper with red writing on them sitting on a table next to each other

Running this code will create a simple to-do list application with a main window for viewing tasks and a toplevel window for adding new tasks. Users can click the "Add Task" button in the main window to open the toplevel window and input a new task. Once they submit the task, it will be added to the to-do list in both windows.

Now that you have seen an example of using Tkinter's toplevel widget, you can explore and experiment with other Tkinter widgets and methods to create more advanced GUI applications. Happy coding!