- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Disable the underlying window when a popup is created in Python TKinter
We are familiar with popup and used it in many applications. Popup in a tkinter application can be created by creating an instance of Toplevel(root) window. For a particular application, we can trigger the popup on a button object.
Let us create a Python script to close the underlying or the main window after displaying the popup. We can close the main window while residing in a popup window by using the withdraw() method.
Through this example, we will create a popup dialog that can be triggered after clicking a button. Once the popup will open, the parent window will close automatically.
#Import the required library from tkinter import* #Create an instance of tkinter frame win= Tk() #Define geometry of the window win.geometry("750x250") #Define a function to close the popup window def close_win(top): top.destroy() win.destroy() #Define a function to open the Popup Dialogue def popupwin(): #withdraw the main window win.withdraw() #Create a Toplevel window top= Toplevel(win) top.geometry("750x250") #Create an Entry Widget in the Toplevel window entry= Entry(top, width= 25) entry.insert(INSERT, "Enter Your Email ID") entry.pack() #Create a Button Widget in the Toplevel Window button= Button(top, text="Ok", command=lambda:close_win(top)) button.pack(pady=5, side= TOP) #Create a Label label= Label(win, text="Click the Button to Open the Popup Dialogue", font= ('Helvetica 15 bold')) label.pack(pady=20) #Create a Button button= Button(win, text= "Click Me!", command= popupwin, font= ('Helvetica 14 bold')) button.pack(pady=20) win.mainloop()
When we execute the above code snippet, it will display a window.
Now click the "Click Me" button. It will open a Popup window and close the parent window.
- How do I create a popup window in Tkinter?
- How do I create a popup window using Tkinter?
- Disable Exit (or [ X ]) in Tkinter Window
- How do I create a popup window using Tkinter Program?
- Resize the Tkinter Listbox widget when the window resizes
- Dynamically Resize Buttons When Resizing a Window using Tkinter
- How to get a Popup Dialog in Tkinter/Python?
- Creating a Transparent window in Python Tkinter
- Creating a Frameless window in Python Tkinter
- Initialize a window as maximized in Tkinter Python
- How to create a Popup Menu in Tkinter?
- What is the correct way to implement a custom popup Tkinter dialog box?
- Execute a script when the browser window is closed in HTML?
- How to disable a Combobox in Tkinter?