![]() |
In this article, we will be discussing how to close only the TopLevel window in Python Tkinter. Syntax:
Stepwise ImplementationStep 1: First of all, import the library tkinter. from tkinter import * Step 2: Now, create a GUI app using tkinter app=Tk() Step 3: Next, give a title to the app.
Step 4: Further, make a function to create a TopLevel window which will be opened when pressed a button on the GUI app. def top_level(): Step 4.1: In the function, create a TopLevel Window first. top = Toplevel() Step 4.2: Moreover, create a title and set the geometry for the TopLevel window.
Step 4.3: Later on, display a message in the TopLevel window.
Step 4.4: Furthermore, make a function for creating an exit button which when clicked will close the TopLevel window. def exit_btn(): top.destroy() top.update() Step 4.5: In addition to it, create an exit button for closing the TopLevel window.
Step 5: Now, declare a button on GUI app, which when clicked will deviate you to the TopLevel window.
Step 6: Finally, make an infinite loop for displaying the app on the screen. app.mainloop() Example: Python3
Output: |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |