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.expression = Entry(self) self.expression.pack() self.alertButton = Button(self, text='Evaluate it!', command=self.compute) self.alertButton.pack() def compute(self): expression = self.expression.get() or '0' messagebox.showinfo('Result', '%s = %s' % (expression, eval(expression))) app = Application() # 设置窗口标题: app.master.title("Please input math expression") # 主消息循环: app.mainloop()
Sign in to make a reply
遥望君山