In this lesson we want to learn how to Build Multi Window Application with Python & TKinter, Tkinter is standard GUI (Graphical User Interface) library for Python. It provides a set of tools for creating graphical user interfaces that are portable across multiple platforms, including Windows, macOS and Linux. Tkinter provides simple and intuitive way to create windows, dialogs, buttons, labels and other GUI elements using Python. with Tkinter, you can create different types of applications from simple desktop applications to more complex ones, such as data visualization tools, game and multimedia players. Tkinter is included with most Python installations and is easy to learn and use, making it a popular choice for many Python developers.
Build Multi Window Application with Python & TKinter
To create multi window applications with Python Tkinter, you can use Tk() method to create multiple Tkinter windows, each with its own set of widgets. to switch between windows, you can use the withdraw() method to hide window and the deiconify() method to show window. this is an example to get started:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import tkinter as tk def show_second_window(): second_window = tk.Toplevel(root) second_window.title("Second Window") second_window.geometry("200x100") label = tk.Label(second_window, text="This is the second window.") label.pack() root = tk.Tk() root.title("Main Window") root.geometry("200x100") button = tk.Button(root, text="Open Second Window", command=show_second_window) button.pack() root.mainloop() |
In this example show_second_window() function creates new Toplevel window when the “Open Second Window” button is clicked. Toplevel window acts as separate window with its own title and geometry, and can be manipulated independently of the main window. to switch between windows, you can use the withdraw() and deiconify() methods. Note that you should always keep a reference to each window, so you can manipulate it later if needed.
Run the complete code and this will be the result
Learn More on Python
- Python Best Libraries for Web Development
- How to Make an Instagram Bot
- How to send Message to Instagram with Python
- Build Python REST API with FastAPI
- Python Best Frameworks for Web Development
- How to Build Charts in TKinter
- How to Install TKinter in Windows and Linux