首页 > 电脑

这段Python指令哪里出了问题

更新时间2022-08-04 08:31:51

指令如下:
from tkinter import *
root = Tk()
root.title('calculator')
a = Variable()
e1 = Entry(root,width=28,bd=0,textvariable=a)
e1.place(x=0,y=0)
def a():    
     a.set(1)
Button(root,text='1',width=3,height=1,bd=1,command=a).place(x=0,y=20)
root.mainloop()
每次点击按钮时老是报错:
AttributeError: 'function' object has no attribute 'set'
(Python3.7)

你的a既定义了变量,又把它定义成了函数,当然是不对的,改函数为其它的如b就可以了

这段Python指令哪里出了问题

上一篇:如何设置HalouSmartWatch2的时间和日期

下一篇:怎样在python的turtle库里用for循环填充不同颜色?