- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- 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 to get a Popup Dialog in Tkinter/Python?
Tkinter is a standard Python library that is used to create and develop GUI-based applications. We can create an application in Tkinter and add widgets to it that make the application more interactive.
Let's suppose we want to show a popup dialog in an application. In this case, we can use the built-in messagebox module in tkinter. It allows us to show the various dialog boxes such as errors, info box, confirmation boxes, etc.
Example
In this example, we've created a button, which upon clicking will show a popup message on the screen.
# Import the required library from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x250") # Define a button to show the popup message box def on_click(): messagebox.showinfo("Message", "Hey folks!") # Add a Label widget Label(win, text="Click the button to open a popup", font=('Georgia 13')) # Create a button to open the popup dialog ttk.Button(win, text="Open Popup", command=on_click).pack(pady=30) win.mainloop()
Output
Running the above code will display a window with a button to open a dialog box.
Click the button to show the popup dialog box on the screen.
Advertisements