https://docs.python.org/3.7/library/tkinter.html
参考官方文档
# 面向对象的GUI
#frame是一个虚拟的框架,作为容器放置其他组件,从而实现复杂布局
class Application(Frame):#继承自Frame
def __init__(self,master=None):
super().__init__(master) #调用父类Frame的构造方法
self.master = master;
self.pack()
self.creatWidget()
def creatWidget(self):#其实这个发放就是创建并配置组件
self.btn = Button(self)
self.btn['text'] = "点击送魔方"
self.btn['command'] = self.sendFlowers
self.btn.pack()
self.btnQuit = Button(self,text="退出",command=root.destroy)
self.btnQuit.pack()
def sendFlowers(self):
messagebox.showinfo("送魔方","魔方来了,接受呀")
root = Tk()
root.geometry("400x100+200+300")
root.title("hello")
#师傅是root
app = Application(master=root)
root.mainloop()