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.


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

# Set the geometry

# 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)



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.

Updated on 05-Aug-2021 14:10:23