我试图从父类访问变量。但它似乎没有用。
这是我缩短的原始代码,以显示基本行:
class Parent_Class(GUI):
def __init__(self,hdf5w,master):
self.frameFilter = Frame(self.frameDataset)
self.frameFilter.grid(row=3,column=0,sticky='wen')
# I shortened framefilter definition here.
self.filter0 = Listbox(self.frameFilter,exportselection=0)
self.filter0.grid(row=1,column=0,sticky='wen')
self.filter0.bind('<<ListboxSelect>>', self.onSelectFilter0)
def onSelectFilter0(self,evt):
self.datasetsfilter = self.ohdf5.getDatasets(self.ohdf5.filterGroupPath)
# Here is an exemple of variable that I will try to use below in extended class.
for dataset in self.datasetsfilter:
self.dataset_listbox.insert(i,dataset)
i+=1
def export(self):
new_window2 = Toplevel(self.frameFile)
w = ExportGUI(new_window2)
class Extended_Class(Parent_Class):
def __init__(self, master):
self.master = master
self.master.title("Export")
self.master.geometry('200x200')
export_selected = Button(self.master, text = 'Export filters',command=self.export_filter)
export_selected.place(x=20, y=50)
self.master.mainloop()
def export_filter(self):
a = self.ohdf5.datasetsfilter
print('EXPORTING')
print(a)
所以我收到以下错误消息:
Exception in Tkinter callback Traceback (most recent call last): File "C:\ProgramData\Anaconda2\lib\lib-tk\Tkinter.py", line 1542, in call return self.func(*args) File "GUI\GUI.py", line 384, in export_filter a = self.ohdf5.datasetsfilter AttributeError: ExportGUI instance has no attribute 'ohdf5' 我找到了这个主题:如何在python中访问父类的实例变量?我有完全相同的错误代码。但我的变量datasetsfilter已经定义,self所以它不会工作。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。