- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 Program?
Tkinter has many inbuilt functions and features which can be used to extend the internal functionality of an application. Popups in Tkinter are created by defining the messagebox. In order to work with the popup message boxes, you have first to import the messagebox package in Tkinter by the command "import tkinter.messagebox".
In this example, we will create a messagebox popup with a question. On clicking a particular option, it will redirect the user to the respective operation.
# Import the required libraries from tkinter import * import tkinter.messagebox # Create an instance of Tkinter Frame win = Tk() # Set the geometry of Tkinter Frame win.geometry("700x350") def open_win(): out = tkinter.messagebox.askquestion('Prompt', 'Do you want to Continue?') if out == 'yes': Label(win, text="Thank You for your Response!", font=('Helvetica 22 bold')).pack(pady=40) else: win.destroy() # Create a Button button = Button(win, text="Click Me", command=open_win, font=('Helvetica 14 bold'), foreground='OrangeRed3',background="white") button.pack(pady=50) win.mainloop()
On executing the above code, it will display the following window −
Now, click the "Click Me" button. It will show a messagebox with a question.
Next, click the "Yes" button on the messagebox. It will display the following window −
- How do I create a popup window using Tkinter?
- 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 to create a Popup Menu in Tkinter?
- How do I set a minimum window size in Tkinter?
- How do I position the buttons on a Tkinter window?
- How do I create an automatically updating GUI using 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 get the width and height of a Tkinter window?
- Disable the underlying window when a popup is created in Python TKinter