- 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
How do I create a popup window using Tkinter?
Tkinter supports toplevel classes, and these classes contain toplevel window. Toplevel window is also known as child window. We can create a toplevel window by creating the object of Toplevel(parent).
The toplevel window inherits all the properties of Tkinter's parent object. It can contain widgets, frames, canvas and other objects as well.
In this example, we will create a button that will open a popup window.
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x250") def open_win(): #Create a Button to Open the Toplevel Window top= Toplevel(win) top.geometry("700x250") top.title("Child Window") #Create a label in Toplevel window Label(top, text= "Hello World!") Label(win, text= "Click the button to Open Popup Window", font= ('Helvetica 18')).place(relx=.5, rely=.5, anchor= CENTER) Button(win, text= "Click Me", background= "white", foreground= "blue", font= ('Helvetica 13 bold'), command= open_win).pack(pady= 50) win.mainloop()
Running the above code will display a window with a Label and a button.
Now, clicking the button will open a New Popup window.
- How do I create a popup window using Tkinter Program?
- How do I create a popup window in Tkinter?
- How do I close a tkinter window?
- How do I open a website in a Tkinter window?
- How do I set a minimum window size in Tkinter?
- How do I position the buttons on a Tkinter window?
- How to create a Popup Menu in Tkinter?
- How do I insert a JPEG image into a Python Tkinter window?
- How do I handle the window close event in Tkinter?
- How do I use Window Manager (wm) attributes in Tkinter?
- How do I create an automatically updating GUI using Tkinter?
- How do I create a date picker in tkinter?
- How do I get the width and height of a Tkinter window?
- How do I get rid of the Python Tkinter root window?