@@ -45,18 +45,30 @@ def __init__(self, container, *args, **kwargs):
4545 "<Configure>" ,
4646 lambda event : self .canvas .configure (scrollregion = self .canvas .bbox ("all" )),
4747 )
48- self .canvas .create_window ((0 , 0 ), window = self .scrollable_frame , anchor = "nw" )
48+ self .canvas_frame_id = self .canvas .create_window (
49+ (0 , 0 ), window = self .scrollable_frame , anchor = "nw"
50+ )
4951 self .scrollbar = tkinter .ttk .Scrollbar (
5052 self , orient = "vertical" , command = self .canvas .yview
5153 )
5254 self .canvas .configure (yscrollcommand = self .scrollbar .set )
53- self .canvas .pack (side = "left" , fill = "both" , expand = True )
54- self .scrollbar .pack (side = "right" , fill = "y" )
55+ self .canvas .pack (side = "left" , fill = tkinter .BOTH , expand = True )
56+ self .scrollbar .pack (side = "right" , fill = tkinter .Y )
57+
58+ # update the inner content frame when the canvas resizes
59+ self .canvas .bind ("<Configure>" , self ._resize_canvas_frame )
5560
5661 # bind mouse scroll only when the mouse is over our element
5762 self .canvas .bind ("<Enter>" , self ._bind_mouse )
5863 self .canvas .bind ("<Leave>" , self ._unbind_mouse )
5964
65+ def _resize_canvas_frame (self , event ):
66+ """Resize the width of the inner content frame"""
67+ # Note that we intentionally do NOT update the height of the inner
68+ # frame. We want that to be based on the amount of content so that we
69+ # can scroll it.
70+ self .canvas .itemconfig (self .canvas_frame_id , width = event .width )
71+
6072 def _bind_mouse (self , event ):
6173 if sys .platform == "linux" :
6274 self .canvas .bind_all ("<Button-4>" , self ._on_mouse_scroll )
@@ -131,7 +143,7 @@ def _render_edit_mode(self):
131143
132144 @property
133145 def pencil_icon (self ):
134- """ ... note:: Make sure to store a reference to the result, as the
146+ """... note:: Make sure to store a reference to the result, as the
135147 BitmapImage may otherwise get garbage collected. Passing it to
136148 tkinter.Label is not sufficient.
137149 (https://stackoverflow.com/a/31959529/2796349)
0 commit comments