from tkinter import *from math import * def btnClick(numbers): global operator operator=operator + str(numbers) text_input.set(operator)def btnClearDisplay(): global operator operator="" text_input.set=("")def btnEqualsInput(): global operator sumup=str(eval(operator)) text_input.set(operator) operator=""cal = Tk()cal.title("Calculator")operator = ""text_input = StringVar()txtDisplay = Entry(cal,font=("Helvetica", 15, 'italic'), textvariable=text_input, bd=18, insertwidth=4, bg="grey", justify='right') .grid(columnspan=4)btn7=Button(cal,padx=12,bd=8, fg="black", font=('arial',15,'bold'), text='7',command=lambda:btnClick(7), bg="silver") .grid(row=1,column=0)btn8=Button(cal,padx=12,bd=8, fg="black", font=('arial',15,'bold'), text='8',command=lambda:btnClick(8), bg="silver") .grid(row=1,column=1)btn9=Button(cal,padx=12,bd=8, fg="black", font=('arial',15,'bold'), text='9',command=lambda:btnClick(9), bg="silver")
2 回答
DIEA
TA贡献1820条经验 获得超3个赞
您的错误是您没有set正确调用该方法。考虑这个代码:
text_input.set=("")注意=,这意味着您正在销毁该set方法并将其替换为空字符串。相反,您需要set像这样调用方法:
text_input.set("")
LEATH
TA贡献1936条经验 获得超7个赞
对于 = 按钮。
您的代码:
def btnEqualsInput():
global operator
sumup=str(eval(operator))
text_input.set(operator)
operator=""
LAGGY FIX,需要双击,我不知道为什么。
def btnEqualsInput():
global operator
sumup=str(eval(operator))
text_input.set(operator)
operator=sumup
完全固定:
def btnEqualsInput():
global operator
sumup=str(eval(operator))
operator=sumup
text_input.set(operator)
添加回答
举报
0/150
提交
取消
