Tkinter Toplevel

Tkinter Toplevel in Python

Tkinter Toplevel in Python

Interested in above project ,Click Below
WhatsApp
Telegram
LinkedIn

Tkinter Toplevel

In Python’s Tkinter library, the Toplevel widget is used to create and display independent windows that are managed directly by the window manager. These windows can either exist with or without a parent window above them. The Toplevel widget is useful for pop-ups, additional information windows, and grouping related widgets in a separate window.

Toplevel windows come with standard window elements such as title bars, borders, and other decorations provided by the operating system.

Complete Python Course with Advance topics:-Click here

Syntax

The basic syntax for creating a Toplevel window is:

w = Toplevel(options)

Options

The Toplevel widget provides several configuration options to customize the appearance and behavior of the window:

SNOptionDescription
1bgSets the background color of the window.
2bdDefines the border size of the window.
3cursorChanges the mouse pointer when hovered over the window.
4class_Controls whether selected text is exported to the window manager. Setting it to 0 disables this behavior.
5fontDefines the font type of text inside the widget.
6fgSets the foreground color of the window.
7heightSpecifies the window height.
8reliefDefines the border style of the window.
9widthSpecifies the window width.

Methods

The Toplevel widget also provides several methods to control its functionality:

SNMethodDescription
1deiconify()Displays the window if it was previously minimized.
2frame()Returns a system-dependent window identifier.
3group(window)Adds this window to a specific group.
4iconify()Minimizes the window.
5protocol(name, function)Assigns a function to a specific protocol event.
6state()Returns the current state of the window (e.g., normal, iconic, withdrawn).
7transient([master])Makes the window a transient (temporary) window.
8withdraw()Hides the window without destroying it.
9maxsize(width, height)Sets the maximum window size.
10minsize(width, height)Sets the minimum window size.
11positionfrom(who)Specifies the controller for window positioning.
12resizable(width, height)Controls whether the window can be resized.
13sizefrom(who)Specifies the controller for window sizing.
14title(string)Sets the window title.

Example: Creating a New Window using Toplevel

Here’s a simple example demonstrating how to create a new Toplevel window in Tkinter:

See also  Age Calculator in Python with Source Code

from tkinter import *  

root = Tk()  
root.geometry("200x200")  

def open_window():  
    new_window = Toplevel(root)  
    new_window.title("New Window")  
    new_window.geometry("150x150")  

btn = Button(root, text="Open", command=open_window)  
btn.place(x=75, y=50)  

root.mainloop()

Output:

When the button is clicked, a new pop-up window will appear with a specified title and dimensions.

Tkinter Toplevel

Tkinter Toplevel

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE

Conclusion

The Toplevel widget in Tkinter is a powerful tool for managing additional windows in a Python GUI application. Whether you need a pop-up notification, a settings window, or a separate display area, Toplevel provides a simple and effective way to manage multiple windows within your application.

For more Python tutorials and Tkinter guides, stay connected with UpdateGadh!


tkinter toplevel documentation
toplevel tkinter example
tkinter toplevel position
tkinter toplevel always on top
tkinter toplevel modal
tkinter in python
tkinter toplevel geometry
tkinter in python w3schools
tkinter toplevel in python example

    🎓 Need Complete Final Year Project?

    Get Source Code + Report + PPT + Viva Questions (Instant Access)

    🛒 Visit UpdateGadh Store →
    💬 Chat Now