Tkinter提供一个留言框可用于显示各种消息的类, 以便用户可以根据这些消息进行响应。消息, 如确认消息, 错误消息, 警告消息等。
为了使用该类, 必须导入该类, 如下所示:
# import all the functions and constants of this class.
from tkinter.messagebox import *
此类的语法和不同功能的使用–
askokcancel(title=None, message=None, **options)# Ask if operation should proceed;
# return true if the answer is ok.
askquestion(title=None, message=None, **options)# Ask a question.
askretrycancel(title=None, message=None, **options)# Ask if operation should be retried;
# return true if the answer is yes.
askyesno(title=None, message=None, **options)# Ask a question; return true
# if the answer is yes.
askyesnocancel(title=None, message=None, **options)# Ask a question; return true
# if the answer is yes, None if cancelled.
showerror(title=None, message=None, **options)# Show an error message.
showinfo(title=None, message=None, **options)# Show an info message.
showwarning(title=None, message=None, **options)# Show a warning message.
演示各种消息的程序:
# importing messagebox class
from tkinter.messagebox import *
# Showing various messaes
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仅模块留言框molude/class就足够了, 因为这些函数的定义在留言框类。
首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。
评论前必须登录!
注册