如何解决tkinter NameError:名称“表达式”未定义
我是这个Uno计算器的问题,我不得不将它嵌套在一个def中 但现在它不会显示方程式 只是不断得到 表达式=表达式+ str(num) NameError:名称“表达式”未定义
正常运行时效果很好
from tkinter import *
root = Tk()
def Run():
expression = ""
top3 = Tk()
top3.title("score Calqleter")
equation = StringVar()
expression_field = Entry(top3,textvariable=equation)
expression_field.grid(columnspan=4,ipadx=70)
equation.set('click the cards to add')
def press(num):
global expression
expression = expression + str(num)
equation.set(expression)
def equalpress():
try:
global expression
total = str(eval(expression[:-1]))
equation.set(total)
expression = ""
except:
equation.set(" error ")
expression = ""
def clear():
global expression
expression = ""
equation.set("")
button1 = Button(top3,text=' Card1 ',fg='black',bg='red',command=lambda: [press(1),press("+")],height=7,width=7)
button1.grid(row=2,column=0)
button2 = Button(top3,text=' Card2 ',command=lambda: [press(2),width=7)
run = Button(root,text = 'Enter Your Text',command = Run)
run.pack()
root.mainloop()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。