您的位置 首页 > 数码极客

〈messagebox的用法〉messagebox 用法?

本节主要介绍利用Tkin模块下对工具函数创建各式各样的消息框!


消息框使用


Tkinter消息框

在Tkin模块提供创建各式各样消息框对方法

消息框由图标区、提示信息、按钮区组成,生成消息框的工具函数几个参数说明:

  • icon:定制图标的选项,取值:
  • error
  • info
  • question
  • warning
  • type:定制按钮的选项,取值:
  • abort/retry/ignore(取消、重试、忽略)
  • ok(确定)
  • ok/cancel(确定、取消)
  • retry/cancel(重试、取消)
  • yes/no(是、否)
  • yes/no/cancel(是、否、取消)

消息框使用示例:

# -*- coding:utf-8 -*- from tkinter import ttk,Frame,BOTH,LEFT,YES,Tk,StringVar,Radiobutton,TOP,W,X # 导入messagebox from tkinter import messagebox as msgbox class App(object): def __init__(self, mw): = mw () def initWidgets(self): #-----------创建第1个Labelframe,用于选择图标类型----------- topF = Frame() (fill=BOTH) lf1 = (topF, text='请选择图标类型') l(side=LEFT, fill=BOTH, expand=YES, padx=10, pady=5) = StringVar() = [("info", "消息图标"), ("error", "错误图标"), ("question", "问题图标"), ("warning", "告警图标")] # 使用循环创建多个Radiobutton,并放入Labelframe中 for icon in : Radiobutton(lf1, text = icon[1], value=icon[0], variable=).pack(side=TOP, anchor=W) .set("info") #-----------创建第二个Labelframe,用于选择按钮类型----------- lf2 = (topF, text='请选择按钮类型') l(side=LEFT,fill=BOTH, expand=YES, padx=10, pady=5) = StringVar() # 定义所有按钮类型 = [("abortretryignore", "终止、尝试、忽略"), ("ok", "确认"), ("okcancel","确认、取消"), ("retrycancel", "尝试、取消"), ("yesno", "是、否"), ("yesnocancel","是、否、取消")] # 使用循环创建多个Radiobutton,并放入Labelframe中 for tp in : Radiobutton(lf2, text= tp[1], value=tp[0], variable=).pack(side=TOP, anchor=W) .set("okcancel") #-----------创建Frame,用于包含多个按钮来生成不同的消息框----------- bottomF = Frame() bo(fill=BOTH) # 创建8个按钮,并为之绑定事件处理函数 btn1 = (bottomF, text="信息框", command=) b(side=LEFT, fill=X, ipadx=5, ipady=5,pady=5, padx=5) btn2 = (bottomF, text="告警框", command=) b(side=LEFT, fill=X, ipadx=5, ipady=5, pady=5, padx=5) btn3 = (bottomF, text="错误框", command=) b(side=LEFT, fill=X, ipadx=5, ipady=5, pady=5, padx=5) btn4 = (bottomF, text="问答框", command=) b(side=LEFT, fill=X, ipadx=5, ipady=5,pady=5, padx=5) btn5 = (bottomF, text="回答框1", command=) b(side=LEFT, fill=X, ipadx=5, ipady=5,pady=5, padx=5) btn6 = (bottomF, text="回答框2",command=) b(side=LEFT, fill=X, ipadx=5, ipady=5,pady=5, padx=5) btn7 = (bottomF, text="回答框3",command=) b(side=LEFT, fill=X, ipadx=5, ipady=5,pady=5, padx=5) btn8 = (bottomF, text="回答框4",command=) b(side=LEFT, fill=X, ipadx=5, ipady=5,pady=5, padx=5) def showinfo_clicked(self): prin("Info", "showinfo使用.", icon=.get(), type=.get())) def showwarning_clicked(self): prin("Warning", "showwarning使用.", icon=.get(), type=.get())) def showerror_clicked(self): prin("Error", "showerror使用.", icon=.get(), type=.get())) def askquestion_clicked(self): prin("Question", "askquestion使用.", icon=.get(), type=.get())) def askokcancel_clicked(self): prin("OkCancel", "askokcancel使用.", icon=.get(), type=.get())) def askyesno_clicked(self): prin("YesNo", "askyesno使用.", icon=.get(), type=.get())) def askyesnocancel_clicked(self): princancel("YesNoCancel", "askyesnocancel使用.", icon=.get(), type=.get())) def askretrycancel_clicked(self): prin("RetryCancel", "askretrycancel使用.", icon=.get(), type=.get())) if __name__ == "__main__": mw = Tk() mw.title("消息框使用") mw.iconbitmap('leina.ico') App(mw) mw.mainloop()

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“messagebox的用法,messagebox,用法,messagebox函数”边界阅读