📜  Tkinter 中的不同消息 | Python

📅  最后修改于: 2022-05-13 01:55:26.917000             🧑  作者: Mango

Tkinter 中的不同消息 | Python

Tkinter 提供了一个消息框类,可用于显示各种消息,以便用户可以根据这些消息做出响应。消息,如确认消息、错误消息、警告消息等。
为了使用这个类,必须导入这个类,如下所示:

# import all the functions and constants of this class.
from tkinter.messagebox import *


这个类的不同函数的语法和使用——

# Ask if operation should proceed; 
# return true if the answer is ok.

# Ask a question.

# Ask if operation should be retried;
# return true if the answer is yes.

# Ask a question; return true
# if the answer is yes.

# Ask a question; return true
# if the answer is yes, None if cancelled.

# Show an error message.

# Show an info message.

# Show a warning message.


演示各种消息的程序:

Python3
# importing messagebox class
from tkinter.messagebox import *
 
# Showing various messages
 
print(askokcancel("askokcancel", "Ok or Cancel"))
 
print(askquestion("askquestion", "Question?"))
 
print(askretrycancel("askretrycancel", "Retry or Cancel"))
 
print(askyesno("askyesno", "Yes or No"))
 
print(askyesnocancel("askyesnocancel", "Yes or No or Cancel"))
 
print(showerror("showerror", "Error"))
 
print(showinfo("showinfo", "Information"))
 
print(showwarning("showwarning", "Warning"))
 
# print statement is used so that we can
# print the returned value by the function


输出:

注意:请注意,在上面的程序中,我们不必导入 Tkinter 模块,仅messagebox模块/类就足够了,因为这些函数的定义在messagebox类中。