意外的EOF问题tkinter-python



我即将在python中的tkinter中创建一个基本计算器,但由于某种原因,出现了一个意外的EOF问题。由于某种原因,计算机在没有执行所有代码的情况下到达了代码的末尾。我不知道为什么,代码如下:

from tkinter import *
e = Tk(className="Krishna's Calculator")
e.geometry("460x614")
e.resizable(0,0)
def insert(value):
var.set(var.get() + value)
eval(var)
def button(text, width, font, highlightbackground, x, y):
tkinter_button = Button(e, text=text, width=width, command=lambda: insert(text), font=font, highlightbackground=highlightbackground)
tkinter_button.place(x=x, y=y)
def clear():
var.set(" ") 
def equals(vare):
var.set(eval(vare))
helvetica = "Helvetica 50"
arial = "Arial 50 bold"
var = StringVar()
label = Label(e, textvariable = var,bd=5,width=16, relief = SOLID, font = "Arial 50 ",bg="white", fg="black",activebackground="#bb99ff", height = 5,pady = 3)
label.place(x=0,y=0)
button(text = "÷", width=4, font = helvetica, highlightbackground='#8533ff', x = 344, y = 301)
button(text = "×", width=4, font = helvetica, highlightbackground='#8533ff', x = 344, y = 364)
button(text = "-", width=4, font = helvetica, highlightbackground='#8533ff', x = 344, y = 426)
button(text = "+", width=4, font = helvetica, highlightbackground='#8533ff', x = 344, y = 488)
equal = Button(e, text = "=",width=4, command = equals(var.get()), font = "Helvetica 50", highlightbackground='#8533ff')
equal.place(x = 344, y = 551)
aclear = Button(e, text = "AC",width=8, command = clear, font = "Helvetica 50",highlightbackground='#737373')
aclear.place(x = 0, y = 302)
button(text = "%", width=4, font = helvetica,highlightbackground='#737373', x = 228, y = 302)
button(text = ".", width=4, font = arial,highlightbackground='#ffffff', x = 228, y = 550)
button(text = "0", width = 8, font = arial,highlightbackground='#ffffff', x = 0, y = 550)
button(text = "1", width =4, font = arial,highlightbackground='#ffffff', x = 0, y = 488)
button(text = "2", width =4, font = arial,highlightbackground='#ffffff', x = 114, y = 488)
button(text = "3", width=4, font = arial,highlightbackground='#ffffff', x = 228, y = 488)
button(text = "4", width=4, font = arial,highlightbackground='#ffffff', x = 0, y = 426)
button(text = "5", width=4, font = arial,highlightbackground='#ffffff', x = 114, y = 426)
button(text = "6", width=4, font = arial,highlightbackground='#ffffff', x = 228, y = 426)
button(text = "7", width=4, font = arial ,highlightbackground='#ffffff', x = 0, y = 364)
button(text = "8", width=4, font = arial,highlightbackground='#ffffff', x = 114, y = 364)
button(text = "9", width=4, font = arial,highlightbackground='#ffffff', x = 228, y = 364)
e.mainloop()

任何帮助都将不胜感激,泰森!

不定义命令行:

equal = Button(e, text = "=",width=4, command = equals(var.get()), font = "Helvetica 50", highlightbackground='#8533ff')

";equals(("参数需要是一个字符串,例如:

equal = Button(e, text = "=",width=4, command = equals('var.get()'), font = "Helvetica 50", highlightbackground='#8533ff')

试试看。

最新更新