Tkinter is a popular Python library for creating and developing applications. It has various methods and functions that can be used for adding multiple features in an application. Using Tkinter, we can create dialogue boxes and other widgets.
In this article, we will see how we can create a simple message box that will pop up and display some information to select an option.
#Import the required libraries from tkinter import * from tkinter import messagebox #Create an instance of tkinter frame or window win= Tk() #Set the geometry win.geometry("700x100") #Define the function for button def pop_up(): messagebox.showerror("Error! Please check and correct.") messagebox.showwarning("Warning! You can not proceed.") #Create a button Button(win, text="Click",command= pop_up).pack(pady=20) #Keep Running the window win.mainloop()
Running the above code will produce the following window.
If you click the “Click” button, the following error message will pop up.
Again, if you click the “OK” button, it will pop up the following warning message.