10
10
class ScrollableFrameTk (ttk .Frame ):
11
11
"""
12
12
Container with horizontal and vertical scrolling capabilities. Widgets must
13
- be added to its `frame` attribute.
13
+ be added to its ``frame`` attribute. Constructor arguments are passed to
14
+ the parent constructor.
14
15
"""
15
16
16
17
def __init__ (self , * args , ** kwargs ):
@@ -45,16 +46,16 @@ def __init__(self, *args, **kwargs):
45
46
self ._canvas .xview_moveto (0.0 )
46
47
self ._canvas .yview_moveto (0.0 )
47
48
48
- def _xview (self , * args , width = None ):
49
+ def _xview (self , * args , width : int | None = None ):
49
50
"""
50
51
Called when a horizontal scroll is requested. Called by other callbacks
51
- (`_on_canvas_configure` and `_on_frame_configure`) whenever it is
52
+ (`` _on_canvas_configure`` and `` _on_frame_configure` `) whenever it is
52
53
necessary to horizontally realign the contents of the canvas. Scroll
53
54
the view only if the contents are not completely visible. Otherwise,
54
55
move the scrollbar to such a position that they are horizontally
55
56
centred.
56
57
57
- :param args: Tuple which can be passed to `tkinter.Canvas.xview`.
58
+ :param args: Passed to `` tkinter.Canvas.xview` `.
58
59
:param width: Width of the canvas.
59
60
"""
60
61
if self ._canvas .xview () != (0.0 , 1.0 ):
@@ -73,12 +74,12 @@ def _yview(self, *args):
73
74
Called when a vertical scroll is requested. Scroll the view only if the
74
75
contents are not completely visible.
75
76
76
- :param args: Tuple which can be passed to `tkinter.Canvas.yview`.
77
+ :param args: Passed to `` tkinter.Canvas.yview` `.
77
78
"""
78
79
if self ._canvas .yview () != (0.0 , 1.0 ):
79
80
self ._canvas .yview (* args )
80
81
81
- def _on_canvas_configure (self , event ):
82
+ def _on_canvas_configure (self , event : tk . Event ):
82
83
"""
83
84
Called when the canvas is resized. Update the scrollable region.
84
85
@@ -87,22 +88,22 @@ def _on_canvas_configure(self, event):
87
88
self ._canvas .configure (scrollregion = self ._canvas .bbox (tk .ALL ))
88
89
self ._xview (tk .SCROLL , 0 , tk .UNITS , width = event .width )
89
90
90
- def _on_frame_configure (self , _ = None ):
91
+ def _on_frame_configure (self , _event : tk . Event | None = None ):
91
92
"""
92
93
Called when the frame is resized or the canvas is scrolled. Update the
93
94
scrollable region.
94
95
95
96
This method is necessary to handle updates which may occur after the
96
97
GUI loop has started.
97
98
98
- :param _ : Configure event.
99
+ :param _event : Configure event.
99
100
"""
100
101
self ._canvas .configure (scrollregion = self ._canvas .bbox (tk .ALL ))
101
102
self ._xview (tk .SCROLL , 0 , tk .UNITS )
102
103
103
- def _on_frame_expose (self , _ = None ):
104
+ def _on_frame_expose (self , _event : tk . Event | None = None ):
104
105
"""
105
- Called when the frame becomes visible. Call `_on_frame_configure` and
106
+ Called when the frame becomes visible. Call `` _on_frame_configure` ` and
106
107
then disable this callback.
107
108
108
109
This method is necessary because if a scrollable frame is put into,
@@ -112,34 +113,34 @@ def _on_frame_expose(self, _=None):
112
113
because its frame configure events work differently.) Hence, I try to
113
114
centre the contents again upon an expose event.
114
115
115
- :param _ : Expose event.
116
+ :param _event : Expose event.
116
117
"""
117
118
self ._on_frame_configure ()
118
119
self .frame .unbind ("<Expose>" , self ._on_frame_expose_id )
119
120
120
- def _on_canvas_enter (self , _ = None ):
121
+ def _on_canvas_enter (self , _event : tk . Event | None = None ):
121
122
"""
122
123
Called when the mouse pointer enters the canvas. Set up vertical
123
124
scrolling with the mouse wheel.
124
125
125
- :param _ : Enter event.
126
+ :param _event : Enter event.
126
127
"""
127
128
self .bind_all ("<Button-4>" , self ._on_mouse_scroll )
128
129
self .bind_all ("<Button-5>" , self ._on_mouse_scroll )
129
130
self .bind_all ("<MouseWheel>" , self ._on_mouse_scroll )
130
131
131
- def _on_canvas_leave (self , _ = None ):
132
+ def _on_canvas_leave (self , _event : tk . Event | None = None ):
132
133
"""
133
134
Called when the mouse pointer leaves the canvas. Unset vertical
134
135
scrolling with the mouse wheel.
135
136
136
- :param _ : Leave event.
137
+ :param _event : Leave event.
137
138
"""
138
139
self .unbind_all ("<Button-4>" )
139
140
self .unbind_all ("<Button-5>" )
140
141
self .unbind_all ("<MouseWheel>" )
141
142
142
- def _on_mouse_scroll (self , event ):
143
+ def _on_mouse_scroll (self , event : tk . Event ):
143
144
"""
144
145
Called when the mouse wheel is scrolled or a two-finger swipe gesture
145
146
is performed on the touchpad. Ask to scroll the view horizontally if
0 commit comments