Dialogs are windows popped up by a script to provide or request additional information. Dialogs are generally implemented with the 'Toplevel' window object.
Tkinter comes with a collection of precoded (modal) dialog windows and they are called 'standard dialogs' or 'common dialogs'.
# dialog1.py
import tkinter as tk # Py3
from tkinter import messagebox
root = tk.Tk()
def callback():
if messagebox.askyesno("Verify", "Do you really want to quit?"):
messagebox.showwarning("Yes", "Quit not implemented")
else:
messagebox.showinfo("No", "Quit has been cancelled")
button1 = tk.Button(root, text="Quit", command=callback)
button1.grid(sticky=tk.EW)
button2 = tk.Button(root, text="Spam", command=lambda:
messagebox.showerror("Error", "Error message"))
button2.grid(sticky=tk.EW)
root.mainloop()
# The first group of standard dialogs is used to present information.
messagebox.showinfo("Info", "Some info")
messagebox.showwarning("Warning", "Warning message")
messagebox.showerror("Error", "Error message")
# The second group is used to ask questions.
reply = messagebox.askquestion("Title", "Question?") # return yes/no
reply = messagebox.askokcancel("Title", "Proceed?") # return True/False
reply = messagebox.askretrycancel("Title", "Try again?") # return True/False
reply = messagebox.askyesno("Print", "Print this report?") # return True/False
reply = messagebox.askyesnocancel("Print", "Print this report?") # return True/False/None