'''测试一个经典的GUI程序的写法,使用面向对象的方式'''
from tkinter import *
from tkinter import messagebox
class Application(Frame):
'''一个经典的GUI程序的类的写法'''
def __init__(self,master=None):
super().__init__(master)#super()代表的是父类的定义,而不是父类对象
self.master=master
self.pack()
self.creatWidget() # 通过这种方式进行调用
def creatWidget(self):
'''创建新组建'''
self.label01=Label(self,text="百战程序员",width=10,height=2,
bg="black",fg="white")
self.label01.pack()
self.label02=Label(self,text="百战程序员",width=10,height=2,
bg="pink",fg='white',font=('楷体',30))
self.label02.pack()
#显示图像
global photo
photo = PhotoImage(file="cyx.gif")#创建一个图片对象
self.label03=Label(self,image=photo)#利用image参数对这个标签进行赋值
self.label03.pack()
self.label04=Label(self,text="sd\nsdf\n",
borderwidth=1,relief="solid",justify="right")
self.label04.pack()
self.but01=Button(self,text="quit",command=root.destroy())
def songhua(self):
messagebox.showinfo("pythonGUI/florwer","99") #第一个是框框的标题,第二个是框框里的内容
if __name__=="__main__":
root=Tk()
app=Application(master=root)
root.geometry('200x100+300+300')
root.mainloop()
老师,我想加一个退出的button,但是这个一直报错,请问是为什么