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.helloLabel = Label(self, text='Hi')
self.helloLabel.pack()
self.quitButton = Button(self, text='退出', command=self.quit)
self.quitButton.pack()
self.input = Entry(self)
self.input.pack()
self.nameButton = Button(self, text='Hello', command=self.hello)
self.nameButton.pack()
def hello(self):
name = self.input.get()
messagebox.showinfo('对话框', 'Hello,%s' % name)
app = Application()
app.master.title("窗口标题")
app.master.geometry("400x300")
app.mainloop()