AttributeError: object has no attribute?(AttributeError:对象没有属性?)
本文介绍了AttributeError:对象没有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,这是我收到的错误: AttributeError:‘Des’对象没有‘ASMULT_OUTPUT’属性这就是我正在尝试做的事情。
当我在此框架上时,我正在创建一个文本变量,然后将其发送到Set类。
class upload_csv(Frame):
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master, width=250, height=160, bg='white')
self.upload_csv_btn = Button(
self.frame,
text="Add Data Source",
fg="DodgerBlue4",
font=("Graph Type", 15),
height=1, width=20,
borderwidth=2,
relief="groove",
command=self.upload)
self.upload_csv_btn.place(x=10, y=10)
self.frame.pack()
def upload(self):
global text
self.xvalues = []
self.yvalues = []
self.xyvalues = []
self.header = []
filename = filedialog.askopenfilename()
if len(filename) != 0:
print('Selected:', filename)
with open(filename) as file:
csvreader = csv.reader(file)
self.header.append(next(csvreader))
for row in csvreader:
if len(row) == 3:
self.xvalues.append(int(row[0]))
self.yvalues.append(int(row[1]))
self.xyvalues.append(int(row[2]))
text = (
self.header[0][0]+ ": " + str(self.xvalues).replace('[','').replace(']','') +
"
" + self.header[0][1] + ": " + str(self.yvalues).replace('[','').replace(']','') +
"
" + self.header[0][2] + ": " + str(self.xyvalues).replace('[','').replace(']',''))
elif len(row) == 2:
self.xvalues.append(row[0])
self.yvalues.append(row[1])
text = (
self.header[0][0] + ": " + str(self.xvalues).replace('[','').replace(']','') +
"
" + self.header[0][1] + ": " + str(self.yvalues).replace('[','').replace(']',''))
# -------------------------------------------------------------------------
s = Set(text)
s.set_summary()
#-----------------------------------------------------------------------
使用Upload类,我通过调用set类和set_sum方法发送变量。使用这个Set类,我将字符串设置为对象项,然后将其发送到我的DES类。我希望在tk文本框元素上设置此项目作为摘要。我在DES类中收到的文本没有问题,但在尝试修改摘要元素时出现以下错误。 我收到的错误:
Traceback (most recent call last):
File "C:Users***AppDataLocalProgramsPythonPython39lib kinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:Users***DocumentsWorkspace******viewupload_csv.py", line 115, in upload
s.set_summary()
File "C:Users***DocumentsWorkspace******viewSet.py", line 14, in set_summary
s.set_summary_text()
File "C:Users***DocumentsWorkspace******view est.py", line 164, in set_summary_text
print(self.summary_output)
AttributeError: 'DES' object has no attribute 'summary_output'
我的Set类:
class Set:
def __init__ (self, summary):
self.summary = summary
def set_summary(self):
print(self.summary)
s = DES(self.summary)
s.set_summary_text()
我的DES类:
class DES(Frame):
def __init__(self, summary):
self.summary = summary
def createFrame(self, master):
self.frame = tk.Frame(master, width=750, height=968,bg='white')
self.summary_output = tk.Text(
self.frame,
height=8,
width=78,
bg="gray95",
borderwidth=2,
relief="groove",
font=("Arial", 12))
self.summary_output.configure(state='disabled')
self.summary_output.place(x=20, y=610)
self.frame.pack()
def set_summary_text(self):
print(self.summary)
print(self.summary_output)
self.summary_output.configure(state='normal')
self.summary_output.delete('1.0', END) # Remote all text
self.summary_output.insert('end',self.summary)
self.summary_output.configure(state='disabled') #Make text widget read only
def main():
global root
root = tk.Tk()
# app = DES(root)
# app = DES.createFrame(root)
s = DES("")
s.createFrame(root)
root.mainloop()
if __name__ == '__main__':
main()
编辑:
所以在尝试回答后,我得到了以下错误,我所做的只是添加了建议:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:Users***AppDataLocalProgramsPythonPython39lib kinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:Users***DocumentsWorkspace\***\***viewupload_csv.py", line 115, in upload
s.set_summary()
File "C:Users\***DocumentsWorkspace\***viewSet.py", line 22, in set_summary
s.createFrame(root)
File "C:Users\***DocumentsWorkspace\***view est.py", line 120, in createFrame
self.canvas.draw() # Create the graph canvas
File "C:Users\***AppDataLocalProgramsPythonPython39libsite-packagesmatplotlibackendsackend_tkagg.py", line 11, in draw
self._master.update_idletasks()
AttributeError: 'str' object has no attribute 'update_idletasks'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:Users\***AppDataLocalProgramsPythonPython39lib kinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:Users\***AppDataLocalProgramsPythonPython39libsite-packagesmatplotlibackends\_backend_tk.py", line 235, in filter_destroy
self._master.update_idletasks()
AttributeError: 'str' object has no attribute 'update_idletasks'
所以我删除了matploy图,并得到以下错误:
所以可能是图表干扰了?我不确定,我需要这个图表。
推荐答案
- 类中的
summary_output
将在createFrame
方法。 - 您首先从
Set.set_summary()
中的DES
类实例化 方法,然后调用它使用的set_summary_text()
方法summary_output
。这是不正确的,因为summary_output
尚未定义。 - 您应该首先调用
createFrame()
方法来定义 属性,然后调用set_summary_text()
以 使用SUMMARY_OUTPUT。
在Set
类中这样做:
class Set:
def __init__ (self, summary):
self.summary = summary
def set_summary(self):
global root
print(self.summary)
s = DES(self.summary)
s.createFrame(root)
s.set_summary_text()
或做任何您认为最适合自己的事情,但您应该先定义summary_output
,然后再定义print
或使用它。
这篇关于AttributeError:对象没有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:AttributeError:对象没有属性?
猜你喜欢
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01