tkinter's message box exercise

Learning reference:

http://www.cnblogs.com/buchizaodian/p/7076964.html


from tkinter import *
import tkinter.messagebox
import tkinter.filedialog

root = Tk()

#Single item prompt box
def tips():
    tkinter.messagebox.showinfo('Tips', 'Life is too short')
def warn():
    tkinter.messagebox.showwarning('Warning', 'There will be rain tomorrow')
of iron():
    tkinter.messagebox.showerror('Error', 'Error')

root.title("Different buttons correspond to different pop-ups")

ti = Button(root,text="提示",command=tips,width=20,height=3)
wa = Button(root,text="警告",command=warn,width=20,height=3)
er = Button(root,text="错误",command=erro,width=20,height=3)

ti.pack ()
wa.pack ()
er.pack ()

#Multiple selection prompt window
def but1():
    a = tkinter.messagebox.askokcancel('Prompt', 'Do you want to perform an operation?')
    print('Returned is True or Flase: ', a)
def but2():
    b = tkinter.messagebox.askquestion('Prompt', 'Do you want to perform an operation?')
    print('return is yes or no: ',b)
def but3():
    c = tkinter.messagebox.askretrycancel('prompt', 'retry or cancel?')
    print('Returned is True or Flase: ',c)
def but4():
    d = tkinter.messagebox.askyesnocancel('Prompt', 'Do you want to perform an operation?')
    print('Returned is true;no;none:',d)
'''
def but5():
    e = tkinter.messagebox.askyesnoretry('Prompt', 'Do you want to perform an operation?')
    print('option is yes; no; retry: ', e)
'''
butt1 = Button(root,text="OK to cancel",command=but1,width=20,height=3)
butt2 = Button(root,text="whether the question is",command=but2,width=20,height=3)
butt3 = Button(root,text="重试取消",command=but3,width=20,height=3)
butt4 = Button(root,text="three options",command=but4,width=20,height=3)
#butt5 = Button(root,text="retry a total of three",command=but5,width=20,height=3)

butt1.pack()
butt2.pack()
butt3.pack()
butt4.pack()
#butt5.pack() does not exist for this


#Open the selected file and output the file path

def but6():
    f = tkinter.filedialog.askopenfilename()
    f1 = tkinter.messagebox.showinfo('Show path',f)
    
butt6 = Button(root,text="Open file, display path",command=but6,width=20,height=3)
butt6.pack()



root.mainloop ()

After defining 6 button functions, use for a in [' ',' '...] to list each content, and then Button=. . . Substitute, more concise

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325500652&siteId=291194637