1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import tkinter from tkinter import messagebox def cmd(): global n global buttontext n += 1 if n==1: messagebox.askokcancel('Python Tkinter', 'askokcancel') buttontext.set('askquestion') elif n==2: messagebox.askquestion('Python Tkinter', 'askquestion') buttontext.set('askyesno') elif n==3: messagebox.askyesno('Python Tkinter', 'askyesno') buttontext.set('showerror') elif n==4: messagebox.showerror('Python Tkinter', 'showerror') buttontext.set('showinfo') elif n==5: messagebox.showinfo('Python Tkinter', 'showinfo') buttontext.set('showwarning') else: n = 0 messagebox.showwarning('Python Tkinter', 'showwarning') buttontext.set('askokcancel') n = 0 root = tkinter.Tk() buttontext = tkinter.StringVar() buttontext.set('askokcancel') button = tkinter.Button(root, textvariable=buttontext, command=cmd) button.pack() root.mainloop() |