I've been trying to instantiate a tkinter scrollbar inside an already working UI. However, all my attempts failed and I'm unable to tell what I'm doing wrong.
I've been trying to add a scrollbar inside the frame "second_frame", inside the StartPage class, which is the one I'm using to show my widgets:
class SampleApp(Tk):
global cnfg #global variable for config (data caching management)
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.geometry('800x800')
# Gianluca: init config
# self.init_config_parser()
container = Frame(self)
container.config(bd=1)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
# Create an instance of StartPage and show it
start_page = StartPage(parent=container, controller=self)
#start_page.grid(row=0, column=0, sticky="nsew")
start_page.pack(fill=BOTH, expand=1)
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
#initialize variables
path_working_directory = StringVar()
my_canvas = Canvas(parent)
my_canvas.pack(side=LEFT, fill=BOTH, expand=1)
my_scrollbar = ttk.Scrollbar(parent, orient=VERTICAL, command=my_canvas.yview)
my_scrollbar.pack(side=RIGHT, fill=Y)
my_canvas.configure(yscrollcommand=my_scrollbar.set)
my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox("all")))
second_frame = Frame(my_canvas)
my_canvas.create_window((0,0), window=second_frame, anchor='nw')
def add_working_directory():
value = askdirectory(title='add_working_directory')
path_working_directory.set(value)
#title
label_title = Label(self, text="Genkidama Migrations", bg="#8F8FBC", fg="white", relief="groove", width=20, font=("Adobe Garamond Pro", 20, "italic"))
label_version = Label(self, text="Version 1.0", bg="#F0F0FF", font=("times new roman", 8, "bold"))
label_title.pack(side="top", fill="x", pady=10)
label_version.place(relx=1.0, rely=0.0, anchor="ne")
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="1",command=add_working_directory).place(x=10, y=58)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="2",command=add_working_directory).place(x=10, y=158)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="31",command=add_working_directory).place(x=10, y=258)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="41",command=add_working_directory).place(x=10, y=358)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="51",command=add_working_directory).place(x=10, y=458)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="61",command=add_working_directory).place(x=10, y=558)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="71",command=add_working_directory).place(x=10, y=658)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="81",command=add_working_directory).place(x=10, y=758)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="91",command=add_working_directory).place(x=10, y=858)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="001",command=add_working_directory).place(x=10, y=958)
Button(second_frame, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="0001",command=add_working_directory).place(x=10, y=1000)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
However, even if the code works, I cant' really see the scrollbar nor the buttonsimage of my current UI. What am I doing wrong?