How to create a pop up message when a button is pressed in Python – Tkinter? Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report In this article, we will see how to create a button and how to show a popup message when a button is pressed in Python. Tkinter is a standard Python Package for creating GUI applications. Tkinter may be a set of wrappers that implement the Tk widgets as Python classes. Python, when combined with Tkinter, provides a quick and straightforward way to create GUI applications. Steps to create a Simple GUI in Python using Tkinter: Import Tkinter package and all of its modules. Create a GUI application root window (root = Tk()) and widgets will be inside the main window. Use mainloop() to call the endless loop of the window. If you forget to call this nothing will appear to the user. The window will await any user interaction till we close it. Syntax : W = Button(root, options) main: Represents the root window. options: Its used for widgets. It can be used as key-value pairs separated by commas. Example 1: Python3 # import everything from tkinter module from tkinter import * # import messagebox from tkinter module import tkinter.messagebox # create a tkinter root window root = tkinter.Tk() # root window title and dimension root.title("When you press a button the message will pop up") root.geometry('500x300') # Create a messagebox showinfo def onClick(): tkinter.messagebox.showinfo("Welcome to GFG.", "Hi I'm your message") # Create a Button button = Button(root, text="Click Me", command=onClick, height=5, width=10) # Set the position of button on the top of window. button.pack(side='bottom') root.mainloop() Output: Output After clicking “Click me” Example 2: Python3 # import everything from tkinter module from tkinter import * # import messagebox from tkinter module import tkinter.messagebox # create a tkinter root window root = tkinter.Tk() # root window title and dimension root.title("When you press a any button the message will pop up") root.geometry('500x300') # Create a messagebox showinfo def East(): tkinter.messagebox.showinfo("Welcome to GFG", "East Button clicked") def West(): tkinter.messagebox.showinfo("Welcome to GFG", "West Button clicked") def North(): tkinter.messagebox.showinfo("Welcome to GFG", "North Button clicked") def South(): tkinter.messagebox.showinfo("Welcome to GFG", "South Button clicked") # Create a Buttons Button1 = Button(root, text="West", command=West, pady=10) Button2 = Button(root, text="East", command=East, pady=10) Button3 = Button(root, text="North", command=North, pady=10) Button4 = Button(root, text="South", command=South, pady=10) # Set the position of buttons Button1.pack(side=LEFT) Button2.pack(side=RIGHT) Button3.pack(side=TOP) Button4.pack(side=BOTTOM) root.mainloop() Output 2: Output After clicking “North” Output After clicking “East” Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 26 Dec, 2020 Like Article Save Article Previous How to change the color and symbol of the cursor in Tkinter? Next How to Extract Text from Images with Python? Share your thoughts in the comments Add Your Comment Please Login to comment...