Tkinter tkMessageBox 具有多种显示消息框的方法。
适用于 Python 2.7 的 Tkinter 和 Python 3 之间略有不同。 要找到您的 Python 版本,请尝试以下命令之一:
python --versionpython3 --version
Tkinter 消息框

TkMessage框显示一个简约的 TkInter 对话框。

Tk 消息框对话框
Tkinter 包括其他几个消息框:
showerror()showwarning()showinfo()
Python 3.x
import tkinterfrom tkinter import messagebox# hide main windowroot = tkinter.Tk()root.withdraw()# message box displaymessagebox.showerror("Error", "Error message")messagebox.showwarning("Warning","Warning message")messagebox.showinfo("Information","Informative message")
Python 2.7
import Tkinterimport tkMessageBox# An error boxtkMessageBox.showerror("Error","No disk space left on device")# A warning boxtkMessageBox.showwarning("Warning","Could not start service")# An information boxtkMessageBox.showinfo("Information","Created in Python.")
您可能会喜欢: Tkinter 问题对话框或更多 Tkinter
