- Trending Categories
- 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 create a message box with Tkinter?
In a particular application, we can create messagebox using messagebox method. Here is the list of messagebox we can create for a particular application,
showinfo() - to show a general message on the screen.
showwarning() - to show the warning to the user.
showerror() - Display error message.
askquestion() - Query the user through the messagebox.
asktocancel() - Display the info to cancel an operation.
askretrycancel() - Display the message to prompt the user to retry again or not.
Example
In this example, we will create an application that will show an info message box after clicking a button.
#Import required libraries from tkinter import * from tkinter import ttk from tkinter import messagebox #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Define a function to show the messagebox def handler(): messagebox.showinfo("Message", "You have clicked a Button") #Create a Label Label(win, text= "Click the below button", font=('Helvetica 16 underline')).pack(pady=20) #Create a Button ttk.Button(win, text= "Click", command= handler).pack(pady=30) win.mainloop()
Output
When we click the Button, it will show a messsagebox,
Advertisements