tkinter.messagebox
— Tkinter message prompts¶
Source code:Lib/tkinter/messagebox.py
Thetkinter.messagebox
module provides a template base class as well asa variety of convenience methods for commonly used configurations. The messageboxes are modal and will return a subset of (True
,False
,None
,OK
,CANCEL
,YES
,NO
) based onthe user’s selection. Common message box styles and layouts include but are notlimited to:

- classtkinter.messagebox.Message(master=None,**options)¶
Create a message window with an application-specified message, an iconand a set of buttons.Each of the buttons in the message window is identified by a unique symbolic name (see thetype options).
The following options are supported:
- command
Specifies the function to invoke when the user closes the dialog.The name of the button clicked by the user to close the dialog ispassed as argument.This is only available on macOS.
- default
Gives thesymbolic name of the default buttonfor this message window (
OK
,CANCEL
, and so on).If this option is not specified, the first button in the dialog willbe made the default.- detail
Specifies an auxiliary message to the main message given by themessage option.The message detail will be presented beneath the main message and,where supported by the OS, in a less emphasized font than the mainmessage.
- icon
Specifies anicon to display.If this option is not specified, then the
INFO
icon will bedisplayed.- message
Specifies the message to display in this message box.The default value is an empty string.
- parent
Makes the specified window the logical parent of the message box.The message box is displayed on top of its parent window.
- title
Specifies a string to display as the title of the message box.This option is ignored on macOS, where platform guidelines forbidthe use of a title on this kind of dialog.
- type
Arranges for apredefined set of buttonsto be displayed.
- show(**options)¶
Display a message window and wait for the user to select one of the buttons. Then return the symbolic name of the selected button.Keyword arguments can override options specified in the constructor.
Information message box
- tkinter.messagebox.showinfo(title=None,message=None,**options)¶
Creates and displays an information message box with the specified titleand message.
Warning message boxes
- tkinter.messagebox.showwarning(title=None,message=None,**options)¶
Creates and displays a warning message box with the specified titleand message.
- tkinter.messagebox.showerror(title=None,message=None,**options)¶
Creates and displays an error message box with the specified titleand message.
Question message boxes
- tkinter.messagebox.askquestion(title=None,message=None,*,type=YESNO,**options)¶
Ask a question. By default shows buttons
YES
andNO
.Returns the symbolic name of the selected button.
- tkinter.messagebox.askokcancel(title=None,message=None,**options)¶
Ask if operation should proceed. Shows buttons
OK
andCANCEL
.ReturnsTrue
if the answer is ok andFalse
otherwise.
- tkinter.messagebox.askretrycancel(title=None,message=None,**options)¶
Ask if operation should be retried. Shows buttons
RETRY
andCANCEL
.ReturnTrue
if the answer is yes andFalse
otherwise.
- tkinter.messagebox.askyesno(title=None,message=None,**options)¶
Ask a question. Shows buttons
YES
andNO
.ReturnsTrue
if the answer is yes andFalse
otherwise.
- tkinter.messagebox.askyesnocancel(title=None,message=None,**options)¶
Ask a question. Shows buttons
YES
,NO
andCANCEL
.ReturnTrue
if the answer is yes,None
if cancelled, andFalse
otherwise.
Symbolic names of buttons:
- tkinter.messagebox.ABORT='abort'¶
- tkinter.messagebox.RETRY='retry'¶
- tkinter.messagebox.IGNORE='ignore'¶
- tkinter.messagebox.OK='ok'¶
- tkinter.messagebox.CANCEL='cancel'¶
- tkinter.messagebox.YES='yes'¶
- tkinter.messagebox.NO='no'¶
Predefined sets of buttons:
- tkinter.messagebox.ABORTRETRYIGNORE='abortretryignore'¶
Displays three buttons whose symbolic names are
ABORT
,RETRY
andIGNORE
.
- tkinter.messagebox.OK='ok'
Displays one button whose symbolic name is
OK
.
- tkinter.messagebox.RETRYCANCEL='retrycancel'¶
Displays two buttons whose symbolic names are
RETRY
andCANCEL
.
- tkinter.messagebox.YESNOCANCEL='yesnocancel'¶
Displays three buttons whose symbolic names are
YES
,NO
andCANCEL
.
Icon images:
- tkinter.messagebox.ERROR='error'¶
- tkinter.messagebox.INFO='info'¶
- tkinter.messagebox.QUESTION='question'¶
- tkinter.messagebox.WARNING='warning'¶