I am trying to create a scroll bar for a window created in my gui using tk.Toplevel. The frame currently often fills up with long grids of strings that are added one buy one. The rest of the GUI allows a user to write to a series of fields which are displayed one after another using a grid.
The data might look something like this:
sadas sfafaf fsaafads fdsafsf dfsfdsf fssfs fsfsfsfs fsfsfs sfsfsfs fsssfsfsf
sadas sfafaf fsaafads fdsafsf dfsfdsf fssfs fsfsfsfs fsfsfs sfsfsfs fsssfsfsf
sadas sfafaf fsaafads fdsafsf dfsfdsf fssfs fsfsfsfs fsfsfs sfsfsfs fsssfsfsf
I used this post: Adding a scrollbar to a group of widgets in Tkinter as a guide to get to where I am right now. Currently, when I open the window the scroll bar appears on the left side. As soon as I add a line the GUI freezes and I have to close it.
Here is the relevant code:
class data_popup():
def __init__(self, parent):
self.parent = parent
self.top = tk.Toplevel(parent)
self.top.title("Current Data")
self.top.protocol('WM_DELETE_WINDOW', self.stop_close)
#Frames
self.header_labels_frame = tk.Frame(self.top)
self.header_labels_frame.pack(side = tk.TOP)
self.data_frame_1 = tk.Frame(self.top)
self.data_frame_1.pack(side = tk.BOTTOM)
self.header_labels_list = []
self.data_canvas = tk.Canvas(self.data_frame_1, borderwidth = 0)
self.data_frame = tk.Frame(self.data_canvas)
self.scrollbar = tk.Scrollbar(self.data_frame, orient = 'vertical', command = self.data_canvas.yview)
self.data_canvas.configure(yscrollcommand = self.scrollbar.set)
self.scrollbar.pack(side = 'right', fill = 'y')
self.data_canvas.pack(side = "bottom", fill = 'both', expand = True)
self.data_canvas.create_window((4,4), window = self.data_frame, anchor = 'nw', tags = "self.frame")
self.data_frame.bind("<Configure>", self.myfunction)
self.create_header()
self.data_row_list = list()
def myfunction(self, event):
self.data_canvas.configure(scrollregion=self.data_canvas.bbox("all"))