为了账号安全,请及时绑定邮箱和手机立即绑定

clearsceeen 和 equal 函数在我的计算器代码中没有响应

clearsceeen 和 equal 函数在我的计算器代码中没有响应

蝴蝶刀刀 2021-06-03 22:25:17
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("")


查看完整回答
反对 回复 2021-06-06
?
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)


查看完整回答
反对 回复 2021-06-06
  • 2 回答
  • 0 关注
  • 201 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号