On the scrollarea Widget
and
Scrollable Widget Containers

by

Csaba Nemethi

csaba.nemethi@t-online.de

Contents

  1. Abstract
  2. The scrollutil::scrollarea Widget
  3. Demo Scripts Related to the scrollutil::scrollarea Widget
  4. Short History of the Mouse Wheel and Its Support in Tk
  5. Mouse Wheel Event Handling in Scrollable Widget Containers
  6. A Demo Script Using the Scrollutil Package and a BWidget ScrollableFrame
  7. A Demo Script Using Scrollutil and Two BWidget ScrollableFrame Widgets

1. Abstract

This is a presentation of the new Scrollutil package, which contains:

The talk shows by means of a series of demo scripts how the scrollutil::scrollarea widget is distinct from all similar widgets, and how to use the mouse wheel event handling provided by the Scrollutil package in BWidget ScrollableFrame widgets.


2. The scrollutil::scrollarea Widget

2.1 Description

The scrollutil::scrollarea mega-widget greatly simplifies the creation of arbitrary scrolled widgets.  It consists of a scrollable widget and two scrollbars connected with that widget.  The display mode of each scrollbar can be static, dynamic, or none.  This widget also respects the header component and title columns of tablelist widgets (this is freely configurable).

Similar widgets and packages:

What makes the scrollutil::scrollarea widget distinct from all the above?

2.2 Quick Reference

Synopsis

package require scrollutil(_tile) ?version?

scrollutil::scrollarea pathName ?options?

Standard options

-background   -highlightbackground  -relief
-borderwidth  -highlightcolor
-cursor       -highlightthickness

Widget-specific options

-respectheader boolean
-respecttitlecolumns boolean
-xscrollbarmode static|dynamic|none
-yscrollbarmode static|dynamic|none

Widget command

pathName cget option
pathName configure ?option? ?value option value ...?
pathName setwidget widget
pathName widget

3. Demo Scripts Related to the scrollutil::scrollarea Widget

3.1 A Scrolled tablelist Widget

Live presentation and review of the following scripts:

The first script contains traditional scrollbar management:

package require tablelist_tile 6.3

wm title . "Scrolled Tablelist"

set f [ttk::frame .f]

# Create the tablelist and the scrollbars as children
# of a frame having -borderwidth 1 and -relief sunken
set frm [ttk::frame $f.frm -borderwidth 1 -relief sunken]
set tbl $frm.tbl
set vsb $frm.vsb
set hsb $frm.hsb
tablelist::tablelist $tbl ... -borderwidth 0 \
    -xscrollcommand [list $hsb set] -yscrollcommand [list $vsb set]
. . .
ttk::scrollbar $vsb -orient vertical   -command [list $tbl yview]
ttk::scrollbar $hsb -orient horizontal -command [list $tbl xview]

. . .

# Manage the widgets within the frame
grid $tbl -row 0 -rowspan 2 -column 0 -columnspan 2 -sticky news
if {[tk windowingsystem] eq "win32"} {
    grid $vsb -row 0 -rowspan 2 -column 2 -sticky ns
} else {
    grid [$tbl cornerpath] -row 0 -column 2 -sticky ew
    grid $vsb              -row 1 -column 2 -sticky ns
}
grid [$tbl cornerpath -sw] -row 2 -column 0 -sticky ns
grid $hsb                  -row 2 -column 1 -sticky ew
grid rowconfigure    $frm 1 -weight 1
grid columnconfigure $frm 1 -weight 1

# Manage the frame
pack $frm -expand yes -fill both -padx 10 -pady 10

. . .

The second script uses a scrollarea widget, which makes it much simpler:

package require tablelist_tile 6.5
package require scrollutil_tile

wm title . "Scrolled Tablelist"

set f [ttk::frame .f]

# Create the tablelist within a scrollarea
set sa [scrollutil::scrollarea $f.sa]
set tbl $sa.tbl
tablelist::tablelist $tbl ...
. . .
$sa setwidget $tbl

. . .

# Manage the scrollarea
pack $sa -expand yes -fill both -padx 10 -pady 10

. . .

3.2 Support for Widgets that Are Scrollable in One Direction Only

Live presentation of the following scripts:

Conclusion:

3.3 The Shimmering Problem in Connection with text Widgets

Live presentation of the following scripts:

Conclusion:


4. Short History of the Mouse Wheel and Its Support in Tk

4.1 History of the Mouse Wheel

4.2 History of the Mouse Wheel Support in Tk


5. Mouse Wheel Event Handling in Scrollable Widget Containers

5.1 How to Use the Mouse Wheel Event Handling of the Scrollutil Package in Scrollable Widget Containers?

5.2 Command Reference

package require scrollutil(_tile) ?version?

scrollutil::createWheelEventBindings ?tag tag ...?

scrollutil::enableScrollingByWheel ?scrollableWidgetContainer scrollableWidgetContainer ...?

scrollutil::adaptWheelEventHandling ?widget widget ...?

scrollutil::setFocusCheckWindow widget ?widget ...? otherWidget

scrollutil::focusCheckWindow widget

6. A Demo Script Using the Scrollutil Package and a BWidget ScrollableFrame

Live presentation and review of the script ScrollableFrmDemo1.tcl ...

package require Tk 8.5
package require BWidget
Widget::theme yes
package require scrollutil_tile

wm title . "European Capitals Quiz"

# Create a ScrollableFrame within a scrollarea
set f  [ttk::frame .f]
set sa [scrollutil::scrollarea $f.sa]
set sf [ScrollableFrame $sa.sf]
$sa setwidget $sf

. . .

# Create mouse wheel event bindings for the binding tag "all" and
# register the ScrollableFrame for scrolling by these bindings
scrollutil::createWheelEventBindings all
scrollutil::enableScrollingByWheel $sf

# Get the content frame and populate it

set cf [$sf getframe]

set countryList {
    Albania Andorra Austria Belarus Belgium "Bosnia and Herzegovina" Bulgaria
    . . .
}
set capitalList {
    Tirana "Andorra la Vella" Vienna Minsk Brussels Sarajevo Sofia
    . . .
}

. . .

set capitalList [lsort $capitalList]

. . .

set row 0
foreach country $countryList {
    . . .

    set w [ttk::combobox $cf.cb$row -state readonly -width 14 \
           -values $capitalList]
    . . .

    # Adapt the handling of the mouse wheel events for the ttk::combobox widget
    scrollutil::adaptWheelEventHandling $w

    . . .

    incr row
}

. . .

7. A Demo Script Using Scrollutil and two BWidget ScrollableFrame Widgets

Live presentation and review of the script ScrollableFrmDemo2.tcl ...

package require Tk 8.5.9                        ;# for ttk::spinbox
package require BWidget
Widget::theme yes
package require mentry_tile 3.2                 ;# for mouse wheel support
package require tablelist_tile 6.5              ;# for -(x|y)mousewheelwindow
                                                ;# and scrollutil::scrollarea
package require scrollutil_tile

wm title . "Scrollutil Demo"

# Create a ScrollableFrame within a scrollarea
set tf [ttk::frame .tf]
set sa [scrollutil::scrollarea $tf.sa]
set sf [ScrollableFrame $sa.sf]
$sa setwidget $sf

. . .

# Get the content frame and populate it
set cf [$sf getframe]
source ScrollableFrmContent.tcl

# Additional stuff related to the mouse wheel events:

# Create mouse wheel event bindings for the binding tag "all" and
# register the ScrollableFrame for scrolling by these bindings
scrollutil::createWheelEventBindings all
scrollutil::enableScrollingByWheel $sf

# Adapt the handling of the mouse wheel events for the text, listbox,
# ttk::combobox, ttk::spinbox, tablelist, and ttk::treeview widgets, as
# well as for the entry components of the mentry widget of type "Date"
set entryList [$me entries]
scrollutil::adaptWheelEventHandling $txt $lb $cb $sb $tbl $tv {*}$entryList

# For the entry components of the mentry widget
# set the "focus check window" to the mentry
scrollutil::setFocusCheckWindow {*}$entryList $me

In the file ScrollableFrmContent.tcl the scrolled text, listbox, tablelist, and ttk::treeview widgets are created within scrollarea widgets:

set _sa [scrollutil::scrollarea ...]
set txt [text $_sa.txt -font TkFixedFont -width 73]
$_sa setwidget $txt
grid $_sa ...

. . .

set _sa [scrollutil::scrollarea ...]
set lb [listbox $_sa.lb -width 0]
$_sa setwidget $lb
grid $_sa ...

. . .

set _sa [scrollutil::scrollarea ...]
set tbl [tablelist::tablelist $_sa.tbl ...]
. . .
$_sa setwidget $tbl
grid $_sa ...

. . .

set _sa [scrollutil::scrollarea ... -borderwidth 0]
set tv [ttk::treeview $_sa.tv ...]
. . .
$_sa setwidget $tv
grid $_sa ...

Live presentation of the procedure configTablelist, contained in the file ScrollableFrmContent.tcl and associated with the "Configure Tablelist Widget" button as the value of its -command option.  It creates a second ScrollableFrame within a scrollarea and invokes: