Next / Previous / Contents

55.1. The tkMessageBox dialogs module

Once you import the tkMessageBox module, you can create any of these seven common types of pop-up menu by calling functions from this table.

Screen shot of askokcancel. .askokcancel(title, message, options)
Screen shot of askquestion. .askquestion(title, message, options)
Screen shot of askretrycancel. .askretrycancel(title, message, options)
Screen shot of askyesno. .askyesno(title, message, options)
Screen shot of showerror. .showerror(title, message, options)
Screen shot of showinfo. .showinfo(title, message, options)
Screen shot of showwarning. .showwarning(title, message, options)

In each case, the title is a string to be displayed in the top of the window decoration. The message argument is a string that appears in the body of the pop-up window; within this string, lines are broken at newline ('\n') characters.

The option arguments may be any of these choices.

default

Which button should be the default choice? If you do not specify this option, the first button (“OK”, “Yes”, or “Retry”) will be the default choice.

To specify which button is the default choice, use default=C, where C is one of these constants defined in tkMessageBox: CANCEL, IGNORE, OK, NO, RETRY, or YES.

icon

Selects which icon appears in the pop-up. Use an argument of the form icon=I where I is one of these constants defined in tkMessageBox: ERROR, INFO, QUESTION, or WARNING.

parent

If you don't specify this option, the pop-up appears above your root window. To make the pop-up appear above some child window W, use the argument parent=W.

Each of the “ask...” pop-up functions returns a value that depends on which button the user pushed to remove the pop-up.