I am trying to output the contents of a database to a Tkinter widget. The database has enough rows and columns to where I need to have both horizontal and vertical scrollbars enabled, but I am having a hard time getting horizontal and vertical scrolling to work simultaneously. I am agnostic about which Tkinter widget is used but here is my current implementation:
# Create root self.root = Tk() self.root.geometry('1000x500+0+0') # Create canvas self.canvas = Canvas(self.root) self.canvas.pack(side=TOP, fill=BOTH, expand=TRUE) # Create scrollbars self.xscrollbar = Scrollbar(self.root, orient=HORIZONTAL, command=self.canvas.xview) self.xscrollbar.pack(side=BOTTOM, fill=X) self.yscrollbar = Scrollbar(self.root, orient=VERTICAL, command=self.canvas.yview) self.yscrollbar.pack(side=RIGHT, fill=Y) # Attach canvas to scrollbars self.canvas.configure(xscrollcommand=self.xscrollbar.set) self.canvas.configure(yscrollcommand=self.yscrollbar.set) # Create frame inside canvas self.frame = Frame(self.canvas) self.canvas.create_window((0,0), window=self.frame, anchor=NW) self.frame.bind('<Configure>', self.set_scrollregion) # Write db contents to canvas self.print_dbcontents() # Invoke main loop self.root.mainloop() def set_scrollregion(self, event): self.canvas.configure(scrollregion=self.canvas.bbox('all')) In this implementation, I can only get scrolling to work in one direction, depending on how I pack the canvas:
self.canvas.pack(side=TOP, fill=BOTH, expand=TRUE) # scrolling works in x but not y self.canvas.pack(side=LEFT, fill=BOTH, expand=TRUE) # scrolling works in y but not x Any suggestions regarding howI just need to get horizontal and vertical scrolling to work simultaneously, or alternative solutions are much appreciatedfind an alternate solution. Thanks!