Base class for Tkinter widgets with scrollbars.
The widget is a standard Tkinter.Frame with an additional configuration option
SCROLLMODE which may be one of "x", "y", "both" or "auto".
If SCROLLMODE is one of "x", "y" or "both", one or two static scrollbars will be
drawn. If SCROLLMODE is set to "auto", two automatic scrollbars that appear only
if needed will be drawn.
The Scrollbar widgets can be accessed with the hbar and vbar class attributes.
Derived classes must override the _setScrolledWidget() method, which must return
the widget that will be scrolled and should add a class attribute that allows
to access this widget, so the _setScrolledWidget() method for a ScrolledListbox
widget might look like:
def _setScrolledWidget(self):
self.listbox = Tkinter.Listbox(self)
return self.listbox
Note that although it should be possible to create scrolled widget classes for
virtually any Listbox or Canvas alike Tkinter widget you can *not* safely use
this class to add automatic scrollbars to a Text or Text alike widget.
This is because in a scrolled Text widget the value of the horizontal scrollbar
depends only on the visible part of the Text, not on it's whole contents.
Thus it may happen that it is the last visible line of text that causes the
automatic scrollbar to be mapped which then hides this last line so it will be
unmapped again, but then it is requested again and gets mapped and so on forever.
There are strategies to avoid this, but usually at the cost that there will be
situations where the horizontal scrollbar remains mapped although it is actually
not needed. In order to acomplish this with the ScrolledWidget class, at least
the _scrollXNow() and _scrollBothNow() methods must be overridden with appropriate
handlers.
Methods
|
|
__init__
cget
configure
destroy
keys
|
|
__init__
|
__init__ (
self,
master=None,
scrollmode='auto',
**kw,
)
|
|
cget
|
cget ( self, key )
|
|
configure
|
configure (
self,
cnf=None,
**kw,
)
|
|
destroy
|
destroy ( self )
|
|
keys
|
keys ( self )
|
|