python2.7使用图形用户界面,进行简单的交互操作。
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 02 09:56:35 2017
@author: user
"""
#import Tkinter
import Tkinter
import tkMessageBox
#def show():
# tkMessageBox.showinfo(title='aaa', message='bbb')
#
#def creatfram():
# root = Tkinter.Tk()
# b = Tkinter.Button(root, text="关于", command=show)
# b.pack()
# root.mainloop()
#creatfram()
def cmd():
global n
global buttontext
n += 1
if n==1:
tkMessageBox.askokcancel('Python Tkinter', 'askokcancel')
buttontext.set('askquestion')
elif n==2:
tkMessageBox.askquestion('Python Tkinter', 'askquestion')
buttontext.set('askyesno')
elif n==3:
tkMessageBox.askyesno('Python Tkinter', 'askyesno')
buttontext.set('showerror')
elif n==4:
tkMessageBox.showerror('Python Tkinter', 'showerror')
buttontext.set('showinfo')
elif n==5:
tkMessageBox.showinfo('Python Tkinter', 'showinfo')
buttontext.set('showwarning')
else:
n = 0
tkMessageBox.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()