该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
————————以下粘贴出部分代码——————————
from tkinter import
#Basic Settings class
class Calculat
def __init__(self,output_string,point,delete):
#就是这儿的事
self.change_output=getattr(self,'change_output')
#明明有output属性
self.output=Label(self.tk, width=39, height=3, font=('Times', 15), anchor='center')
self.output.grid(row=0,column=0,columnspan=5
for row in range(1,4):
for column in range(0,3):
self.default_butt_set(text='%s'%self.button_number,row=row,column=column,
command=operation.change_output(str(self.button_number)))
self.button_number+=1
class Operation(Calculator):
def __init__(self,output_string,point,delete):
#从这里调用
Calculator.__init__(self,output_string,point,delete)
def change_output(self,button_number):
#这里报错
self.output=getattr(Calculator,'output')
#if the variable output_string has had a point, then I can't add another point
if button_number == '.' and self.point == False:
self.output_string += button_number
self.point = True
elif button_number != '.':
self.output_string += button_numbe
if self.delete==True:
self.operation_output.config(text='')
self.delete=False
if len(self.output_string) <= 42:
if self.output_string != '0':
#原来没有getattr的时候就是这报错
self.output.config(font=('Times', 15), text=self.output_string)
else:
self.output_string = '
#get objects
#最早的源头
operation=Operation(output_string,point,delete)
mainloop()
—————————————代码粘贴完毕——————————————
—————————————以下报错信息——————————————
Traceback (most recent call last):
File "D:/FilesOfWzm/Others/Python/计算器(class).py", line 105, in
operation=Operation(output_string,point,delete)
File "D:/FilesOfWzm/Others/Python/计算器(class).py", line 61, in __init__
Calculator.__init__(self,output_string,point,delete)
File "D:/FilesOfWzm/Others/Python/计算器(class).py", line 33, in __init__
self.default_butt_set(text='+',row=1,column=3,command=self.change_output('+'))
File "D:/FilesOfWzm/Others/Python/计算器(class).py", line 64, in change_output
self.output=getattr(Calculator,'output')
AttributeError: type object 'Calculator' has no attribute 'output'
—————————————报错信息粘贴完毕————————————