from
Tkinter
import
*
class
Application(Frame):
def
say_hi(self):#
自定义了一个函数
print
"hi there, everyone!"
def
createWidgets(self):
#
第一个按钮名字叫“QUIT”,并且是红色的字
self.QUIT = Button(self)
self.QUIT[
"text"
] =
"QUIT"
self.QUIT[
"fg"
] =
"red"
self.QUIT[
"command"
] = self.quit #
调用系统的推出命令
self.QUIT.pack({
"side"
:
"left"
})
#
第二个按钮“Hello”
self.hi_there = Button(self)
self.hi_there[
"text"
] =
"Hello"
,
self.hi_there[
"command"
] = self.say_hi #
调用自定义的函数
self.hi_there.pack({
"side"
:
"left"
})
def
__init__(self, master=
None
):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk(
None
,
None
,
'My_Frist_Python_Prog'
)
app = Application(master=root)
app.mainloop()
root.destroy()