I am learning tkinter from the book "Programming Python". In the section dedicated for scroll bars I have faced a problem that I was not able to fix.
from tkinter import *
class ScrolledList(Frame):
def __int__(self, options, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(options)
def hendleList(self, event):
index=self.listbox.curselection()
label=self.listbox.get(index)
self.runCommand(label)
def makeWidget(self, options):
sbar=Scrollbar(self)
list=Listbox(self, relief=SUNKEN)
sbar.config(command=list.yview)
list.config(yscrollcommand=sbar.set)
sbar.pack(side=RIGHT, fill=Y)
list.pack(side=LEFT, expand=YES, fill=BOTH)
pos=0
for label in options:
list.insert(pos, label)
pos+=1
list.bind('<Double-1>', self.handleList)
self.listbox = list
def runCommand(self, selection):
print('You selected:', selection)
if __name__ == '__main__':
options=[('Luberjack-{}'.format(x)) for x in range(20)]
ScrolledList(options).mainloop()
This is my code and the Error being arised:
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/untitled3/venv/scr_list.py", line 34, in <module>
ScrolledList(options).mainloop()
File "C:\Python37-32\lib\tkinter\__init__.py", line 2741, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File "C:\Python37-32\lib\tkinter\__init__.py", line 2289, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Python37-32\lib\tkinter\__init__.py", line 2259, in _setup
self.tk = master.tk
AttributeError: 'list' object has no attribute 'tk'
There was a similar problem before, but I have already called Frame
__init__
in my code