I'm not an expert python programmer. After some time and effort I've built a tkinter UI that properly works. Recently, I've found myself needing to add a scrollbar inside the frame, since I need to place several new buttons inside an already packed UI, and apparently I'm always missing something.
This would be a minimal reproducible example:
class SampleApp(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.geometry('800x800')
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")
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
#initialize variables
path_working_directory = StringVar()
def add_working_directory():
value = askdirectory(title='add_working_directory')
path_working_directory.set(value)
#working directory
Button(self, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="Button1",command=add_working_directory).place(x=10, y=58)
Entry(self, bd="4", textvariable=path_working_directory).place(x=160, y=60)
Button(self, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="Button2",command=add_working_directory).place(x=10, y=250)
Entry(self, bd="4", textvariable=path_working_directory).place(x=160, y=250)
Button(self, overrelief="ridge", bg="#E0E0EE", activebackground="floral white", text="Button3",command=add_working_directory).place(x=10, y=600)
Entry(self, bd="4", textvariable=path_working_directory).place(x=160, y=600)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
This is a working tkinter UI. What I need to add is a scrollbar, so that a user can scroll through the interface and easily see all the buttons. The fact that I'm using classes is making hard for me to understand how to properly add a scrollbar.