Tkinter.Messagebox模块

Messagebox module

1.showinfo(title,message,options)
显示一般的提示信息。
from tkinter import *
from tkinter import messagebox
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.pack()
        self.createWidget()
    def createWidget(self):
        self.button=Button(self,text="退出",command=self.confirm).pack()

    def confirm(self):
        messagebox.showinfo("提示信息:","确定退出吗?")
if __name__ == '__main__':
    root=Tk()
    root.geometry('300x200')
    root.title('萤火虫')
    app=Application(master=root)
    root.mainloop()

Insert picture description here

2.showwarning(title,message,options)
显示警告信息
from tkinter import *
from tkinter import messagebox
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.pack()
        self.createWidget()
    def createWidget(self):
        self.button=Button(self,text="确认",command=self.confirm).pack()

    def confirm(self):
        messagebox.showwarning("提示信息:","病毒入侵")
if __name__ == '__main__':
    root=Tk()
    root.geometry('300x200')
    root.title('萤火虫')
    app=Application(master=root)
    root.mainloop()

Insert picture description here

3.showerror(title,message,options)
显示错误信息

Insert picture description here

4.askquestion(title,message,options)
显示询问消息。传回yes/no

Insert picture description here

5.askokcancel(title,message,options)
显示确定或取消消息。传回True/False

Insert picture description here

6.askyesno(title,message,options)
显示是与否消息。传回True/False

Insert picture description here

7.askyesnocancel(title,message,options)
显示是与否或取消消息。c传回Teue/False/None

Insert picture description here

8.askretrycancel(title,message,options)
显示重试或取消消息。传回True/False

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_44862120/article/details/108014026