from tkinter import *
from tkinter import messagebox
class Application(Frame):
"""一个经典GUI的程序的类的写法"""
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.createWidget()
def createWidget(self):
"""创建组件"""
self.btn01 = Button(self)
self.btn01["text"] = '送花'
self.btn01.pack()
self.btn01["command"] = self.songhua
#创建一个退出按键
self.btnQuit = Button(self, text='退出', command=root.destory)
self.btnQuit.pack()
def songhua(self):
messagebox.showinfo("送花","送你一多玫瑰花,亲亲我吧")
root = Tk()
root.title("我的第一个Gui程序")
root.geometry("600x500+0+0")
app = Application(master=root)
root.mainloop()
D:\Users\asus\PycharmProjects\gui\venv\Scripts\python.exe D:/Users/asus/PycharmProjects/gui/my01.01.py
Traceback (most recent call last):
File "D:/Users/asus/PycharmProjects/gui/my01.01.py", line 34, in <module>
app = Application(master=root)
File "D:/Users/asus/PycharmProjects/gui/my01.01.py", line 13, in __init__
self.createWidget()
File "D:/Users/asus/PycharmProjects/gui/my01.01.py", line 21, in createWidget
self.btn01["command"] = self.songhua
AttributeError: 'Application' object has no attribute 'songhua'
Process finished with exit code 1
