Tkinter messagebox

The best way to display simple dialog boxes in Tkinter is by using the tkinter.messagebox library, which contains several convenient functions that allow you to quickly create common dialog types. Each function displays a preset icon and a selection of buttons with a message and detail text that you specify, and returns a value depending on which button the user clicked.

The following table shows some of the messagebox functions with their icons and return values:

Function Icon Button / return value
askokcancel Question Ok (True), Cancel (False)
askretrycancel Warning Retry (True), Cancel (False)
askyesno Question Yes (True), No (False)
askyesnocancel Question Yes (True), No (False), Cancel (None)
showerror ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.