Python 子类化tk.Listbox时出错(属性错误对象没有属性';tk';)
尝试创建Listbox的子类,以便创建新的KeyListboxPython 子类化tk.Listbox时出错(属性错误对象没有属性';tk';),python,tkinter,listbox,subclass,Python,Tkinter,Listbox,Subclass,尝试创建Listbox的子类,以便创建新的KeyListbox from tkinter import * class KeyListbox(Listbox): def __init__(self,parent,**kwargs): super().__init__(self,parent,**kwargs) root = Tk() root.title("Key List Test") testlist=[ "Python" , "Perl" , "C" , "P
from tkinter import *
class KeyListbox(Listbox):
def __init__(self,parent,**kwargs):
super().__init__(self,parent,**kwargs)
root = Tk()
root.title("Key List Test")
testlist=[ "Python" , "Perl" , "C" , "PHP" , "JSP" , "Ruby"]
lijst = KeyListbox(root,selectmode='multiple')
for i in testlist:
lijst.insert(END,i)
lijst.pack(root)
root.mainloop()
AttributeError:“KeyListbox”对象没有属性“tk”您对
super
使用了错误的语法
class KeyListbox(Listbox):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
或者您可以调用父类,如下所示:
class KeyListbox(Listbox):
def __init__(self, parent, **kwargs):
Listbox.__init__(self, parent, **kwargs)