79181756

Date: 2024-11-12 15:32:50
Score: 1.5
Natty:
Report link

I found an answer thanks to the hint from @acw1668;

I adjusted the <Configure> command to check the size of the scrollregion and compare it to the parent ScrollableFrame class window. If it is smaller, I change the scroll region to be the size of the ScrollableFrame.

Here are the adjustments I made to my class, including changing the window anchor to sit at the top left of the frame;

class ScrollableFrame(ttk.Frame):
    """
    """
    def __init__(self, parent):
        """
        """
        ...
        self.scrollableFrame.bind("<Configure>", self.update_scroll_region)
        ...
        self.canvas.create_window((0, 0), window=self.scrollableFrame, anchor='nw')

    def update_scroll_region(self, event):
        bbox = self.canvas.bbox('all')  
        sfHeight = self.winfo_height()
        if (bbox[3] - bbox[1]) < sfHeight:
            newBbox = (bbox[0], 0, bbox[2], sfHeight)
            self.canvas.configure(scrollregion=newBbox)
        else:
            self.canvas.configure(scrollregion=self.canvas.bbox("all"))
Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @acw1668
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: SPZHunter