继承和访问Python实例变量的问题

2024-09-22 16:24:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我对OOP和GUI都是新手。我正在使用python使用tkinter创建顶级。这个顶级由两个类组成,其中一个继承另一个的属性和实例函数。但我无法读取并获取某个类的init方法中存储的一些值。我该怎么做

我没有办法解决这个问题

班级布局(tk.顶层):

def __init__(self, title, labelName):
    tk.Toplevel.__init__(self)
    self.title(title)

…其他小部件

    self.Scrolly = tk.Scrollbar(self)
    self.Scrollx = tk.Scrollbar(self)
    self.Listbox = tk.Listbox(self)
    self.Listbox.configure(selectmode=tk.MULTIPLE, yscrollcommand=self.Scrolly.set,
                           xscrollcommand=self.Scrollx.set)
    self.Listbox.insert(tk.END, "ciao")
    self.Scrolly.configure(command=self.Listbox.yview())
    self.Scrollx.configure(command=self.Listbox.xview(), orient=tk.HORIZONTAL)
    self.Scrolly.grid(row=1 , column=0, rowspan=5)
    self.Scrollx.grid(row=6, column=1)
    self.Listbox.grid(row=1, column=1, rowspan=5)

与函数关联的其他小部件

def add(self):... #add elements to Listbox

def Remove(self, opt=None):...

类模块功能(布局):

def __init__(self):
    super().__init__("Aggiungi/rimuovi esercizi", "Esercizi:")
    self.Populate_list()
def Populate_list(self):
    print(super().Listbox.get(0, tk.END))

错误: 在列表中 打印(super().Listbox.get(0,tk.END)) AttributeError:“super”对象没有属性“Listbox”


Tags: selftitleinitconfiguredefcolumn顶级tk