I've searched around and cannot seem to find an answer for my problem. I am trying to create a working scrollbar for the following code and cannot seem to get it to work. The problem appears to be with the OnFrameConfigure method. I have seen elsewhere that the method should be def OnFrameConfigure(event):
however when I place the (event)
part into my method it does not work unless I write the function outside of a class
class Main(tk.Tk):
def __init__(self, *args, **kwargs):
'''This initialisation runs the whole program'''
#tk.Tk.__init__(self, *args, **kwargs)
main = tk.Tk()
canvas = tk.Canvas(main)
scroll = tk.Scrollbar(main, orient='vertical', command=canvas.yview)
canvas.configure(yscrollcommand=scroll.set)
frame = tk.Frame(canvas)
scroll.pack(side='right', fill='y')
canvas.pack(side='left', fill='both', expand='yes')
canvas.create_window((0,0), window=frame)
frame.bind('<Configure>', self.OnFrameConfigure(parent=canvas))
for i in range(100):
tk.Label(frame, text='I am a Label').pack()
main.mainloop()
def OnFrameConfigure(self, parent):
'''Used to allowed scrolled region in a canvas'''
parent.configure(scrollregion=parent.bbox('all'))