[ltk-user] Example of scrollbar available?

edgar edgar-rft at web.de
Thu Dec 12 23:43:12 UTC 2013


Am Fri, 13 Dec 2013 00:13:27 +0100
schrieb Josef Wolf <jw at raven.inka.de>:

> On Do, Dez 12, 2013 at 12:27:59 -0800, Jason Miller wrote:
> > ;First make a textbox and a scrollbar to go with it:
> > (let ((tb (make-instance 'text :width 78 :height 20))
> >       (tbsb (make-instance 'scrollbar :orientation :vertical)))
> > ;Now put them where you want them; I'm using pack as it's the least
> > code: (pack tb :side :left)
> >     (pack tbsb :side :left :fill :y) 
> > ;Now you need to tell the two widgets about each other
> >     (configure tbsb "command" (format nil "~a yview" (widget-path
> > tb))) (configure tb :yscrollcommand (format nil "~a
> > set" (widget-path tbsb))))
> 
> Thanks for the hint, Jason! But I am still struggling.
> 
> Your example works fine. But it covers only a single text widget. I
> am trying to scroll a collection of widgets, like this:
> 
> (defun scrolltest ()
>   (with-ltk ()
>     (let* ((root (make-instance 'frame))
>            (button-list (make-instance 'listbox :master root))
>            (scrollbar (make-instance 'scrollbar :master root
>                                      :orientation :vertical))
>            (quit-button (make-instance 'button :master root
>                                        :text "Quit"
>                                        :command (lambda ()
>                                                   (setf
> *exit-mainloop* t)))))
> 
>       (pack root :side :top)
>       (pack quit-button :side :bottom :pady 10)
>       (pack button-list :side :left)
>       (pack scrollbar :side :left :expand t :fill :y)
> 
>       (configure scrollbar "command"
>                  (format nil "~a yview" (widget-path button-list)))
> 
>       (configure button-list :yscrollcommand
>                  (format nil "~a set" (widget-path scrollbar)))
> 
>       (dolist (button-number '(1 2 3 4 5 6 7 8 9 0))
>         (let ((b (make-instance 'button
>                                 :master button-list
>                                 :text button-number
>                                 :command (lambda ()
>                                            (format t "~a~%"
> button-number))))) (pack b :side :top :anchor :w))))))
> 
> The widgets simply don't seem to be connected :-(
> 
> I have also tried with a frame instead of a listbox, but frames don't
> seem to support the yscrollcommand.
> 

The Tcl/Tk code to scroll multiple wigets by a single scrollbar is:

# called by the widget
proc yset {args}  {
  eval [linsert $args 0 .f.sb set]
  yview moveto [lindex [.f.sb get] 0]
}

# called by the scroll bar
proc yview {args}  {
  eval [linsert $args 0 .f.lb1 yview]
  eval [linsert $args 0 .f.lb2 yview]
}

See the Tcl/Tk wiki "multi scrolling" http://wiki.tcl.tk/9254

But it still must be fiddled out how this works with LTK...

- edgar




More information about the ltk-user mailing list