You can accomplish your goal using the scrollbar's -command option.
Whenever the user interacts with the scrollbar, the command you
specified will be called. Additional arguments will be appended
depending on how the scrollbar was used:
* if the left button was clicked, the appended arguments are: scroll
-1 units
* if the right button was clicked: scroll 1 units
* if the left trough was clicked: scroll -1 pages
* if the right trough was clicked: scroll 1 pages
* if the slider was dragged: moveto $location (where $location is a
real number between 0 and 1)
When you respond to scrollbar events, you also need to reposition the
scrollbar to reflect whatever changes have happened. Do this by
calling [$scrollbar set]. Scrollable widgets have -xscrollcommand and -
yscrollcommand options for this purpose; for example, if $text is a
text widget and $yscroll is a vertical scrollbar, your program might
include the line
$text configure -yscrollcommand [list $yscroll set]
When you write the API for your non-standard component, consider
making it as standard as possible, including an -xscrollcommand option
to handle setting the scrollbar and an xview method to respond to
scrollbar events. You might find the snit package helpful for this.