GUI and Desktop Modules

tkinter.messagebox

Displays modal messages and confirmation prompts. Different helpers return different types: askyesno returns a Boolean, whereas askyesnocancel can also return None. Distinguish cancellation from a negative answer. The example mocks the low-level result and tests the wrapper conversion.

Formal Syntax & Structure

python syntaxpython
import tkinter.messagebox

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from tkinter.messagebox import askyesnocancelfrom unittest.mock import patchwith patch("tkinter.messagebox._show", return_value="cancel"):    print(askyesnocancel("Save", "Save changes?"))
Python Reference