Tkinter provides a messagebox class which can be used to show variety of messages so that user can respond according to those messages. Messages like confirmation message, error message, warning message etc.
In order to use this class one must import this class as shown below:
# import all the functions and constants of this class.
from tkinter.messagebox import *
Syntax and uses of different functions of this class –
# Ask if operation should proceed;
# return true if the answer is ok.
# Ask a question.
# Ask if operation should be retried;
# return true if the answer is yes.
# Ask a question; return true
# if the answer is yes.
# Ask a question; return true
# if the answer is yes, None if cancelled.
# Show an error message.
# Show an info message.
# Show a warning message.
Program to demonstrate various messages:
Python3
from tkinter.messagebox import *
print (askokcancel( "askokcancel" , "Ok or Cancel" ))
print (askquestion( "askquestion" , "Question?" ))
print (askretrycancel( "askretrycancel" , "Retry or Cancel" ))
print (askyesno( "askyesno" , "Yes or No" ))
print (askyesnocancel( "askyesnocancel" , "Yes or No or Cancel" ))
print (showerror( "showerror" , "Error" ))
print (showinfo( "showinfo" , "Information" ))
print (showwarning( "showwarning" , "Warning" ))
|
Output:








Note: Note that in above program we don not have to import Tkinter module only messagebox molude/class is sufficient because definitions of these functions is in messagebox class.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
18 Nov, 2021
Like Article
Save Article