GitHub 博客园 Nanakon

图形界面

from tkinter import *
import tkinter.messagebox as messagebox

class Application(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

    def createWidgets(self):
        self.nameInput = Entry(self)
        self.nameInput.pack()
        self.alertButton = Button(self, text='Hello', command=self.hello)
        self.alertButton.pack()

        self.helloLabel = Label(self, text='Hello, world!') #widget
        #pack()方法把Widget加入到父容器中,并实现布局
        self.helloLabel.pack()
        self.quitButton = Button(self, text='Quit', command=self.quit) #widget
        self.quitButton.pack()

    def hello(self):
        name = self.nameInput.get() or 'world'
        messagebox.showinfo('Message', 'Hello, %s' % name)

app = Application()
# 设置窗口标题
app.master.title('Hello World')
# 主消息循环
app.mainloop()

 

posted on 2015-11-30 14:35  jzm17173  阅读(125)  评论(0编辑  收藏  举报

导航

轻音