Two listboxes, one vert scrollbar 
Author Message
 Two listboxes, one vert scrollbar

  I am trying to tie together the scrolling of two listboxes of the same
size to one vertical scrollbar.  I have tried several different things, but
had no success so far.

---piece of code that should work----------------------------

# a frame for the listboxes and scrollbars
frame .lframe

# the two listboxes
listbox .lframe.l -xscrollcommand {.lframe.hor set}\
           -yscrollcommand {.lframe.ver set}\
           -relief sunken
listbox .lframe.l2 -yscrollcommand {.lframe.ver set}\
           -relief sunken

# the two scrollbars
scrollbar .lframe.hor -orient horizontal -command {.lframe.l xview}
scrollbar .lframe.ver -orient vertical -command \
                               {.lframe.l yview; .lframe.l2 yview}

# and the packing
pack .lframe.ver -in .lframe -side right -fill y
pack .lframe.hor -in .lframe -side bottom -fill x
pack .lframe.l -in .lframe -expand 1 -fill both -side right
pack .lframe.l2 -in .lframe -expand 0 -fill both -side left
pack .lframe -fill both -expand 1

---- end code ----------------------------------------------
 Any help will be greatly appreciated.  I'm also interested as to why this
code does not do what I think it should... only one of the two listboxes
actually scrolls.
                           Thanks, Nils.

--



Fri, 15 Aug 1997 12:18:32 GMT  
 Two listboxes, one vert scrollbar

Quote:

>  I am trying to tie together the scrolling of two listboxes of the same
>size to one vertical scrollbar.  I have tried several different things, but
>had no success so far.

>---piece of code that should work----------------------------

># a frame for the listboxes and scrollbars
>frame .lframe

># the two listboxes
>listbox .lframe.l -xscrollcommand {.lframe.hor set}\
>           -yscrollcommand {.lframe.ver set}\
>           -relief sunken
>listbox .lframe.l2 -yscrollcommand {.lframe.ver set}\
>           -relief sunken

># the two scrollbars
>#scrollbar .lframe.hor -orient horizontal -command {.lframe.l xview}

scrollbar .lframe.hor -orient horizontal -command {xScrollProc}

Quote:
>#scrollbar .lframe.ver -orient vertical -command \
>#                               {.lframe.l yview; .lframe.l2 yview}

scrollbar .lframe.ver -orient vertical -command {yScrollProc}

Quote:

># and the packing
>pack .lframe.ver -in .lframe -side right -fill y
>pack .lframe.hor -in .lframe -side bottom -fill x
>pack .lframe.l -in .lframe -expand 1 -fill both -side right
>pack .lframe.l2 -in .lframe -expand 0 -fill both -side left
>pack .lframe -fill both -expand 1

proc xScrollProc {xShift} {
    .lframe.l xview $xShift
    .lframe.l2 xview $xShift
Quote:
}

proc yScrollProc {yShift} {
    .lframe.l yview $yShift
    .lframe.l2 yview $yShift

Quote:
}
>---- end code ----------------------------------------------
> Any help will be greatly appreciated.  I'm also interested as to why this
>code does not do what I think it should... only one of the two listboxes
>actually scrolls.

The problem is that the xview is passed a parameter which doesn't show
up in the code you write.  To use two scrollbars, you have to give that
parameter to both listboxes.  The way to do that is to make a procedure
which receives the added parameter and distributes it to both listboxes.
Actually, the same is true of the set command, except that, in this case,
both list boxes are identifying a single scrollbar, so the added parameter
goes where it needs to without being distributed.

Hope this helps,

Will

P.S., I just coded this off the top of my head, I think it will work
but I didn't actually run it.
--
#      Gravity,                    #    Will Morse
#      not just a good idea,       #    BHP Petroleum (Americas) Inc.
#              it's the law.       #    Houston, Texas

#
#   These are my views and do not necessarly reflect the views of BHP !



Sat, 16 Aug 1997 03:20:06 GMT  
 Two listboxes, one vert scrollbar

Quote:


>>  I am trying to tie together the scrolling of two listboxes of the same
>>size to one vertical scrollbar.  I have tried several different things, but
>>had no success so far.

For help on this, check out the latest issue of UNIX REVIEW
(March 1995) and look at the Cross Thoughts column ("Tickled
Again"). The following code may help:

#
# This proc scrolls a number of listboxes
# all together from one scrollbar.
#
proc multi_scroll { my_scroll args } {

 # Get info on list of args.
 set len [llength $args]

 set elem [expr $len-1]

 # The amount to scroll is
 # the last element of args.
 set amount [lindex $args $elem]

 # Rest of args are widget names.
 set i 0
 while { $i < $elem } {

  set temp_list [lindex $args $i]

  # Scroll list.
  $temp_list yview $amount

  incr i
 }

Quote:
}

# .....

# Area for directories
top_frame .view.dir "Directories"
make_list $dir_list .view.dir.frame.scroll

scrollbar .view.dir.frame.scroll \
  -command "$dir_list yview"
pack .view.dir.frame.scroll \
   -side right -fill y

# Area for files
top_frame .view.fil \
   "Files and Sizes (In Bytes)"
make_list $fil_list .view.fil.frame.scroll
make_list $siz_list .view.fil.frame.scroll

scrollbar .view.fil.frame.scroll \
  -command {multi_scroll \
    .view.fil.frame.scroll \
    $fil_list $siz_list}
pack .view.fil.frame.scroll \
    -side right -fill y

pack .view.dir -side left
pack .view.fil -side right

The above code should be the relevant portions excerpted
from the Tcl script I put together for the article.
If you have any questions, you can contact me.

Good luck,
-Eric
--

CAMAX Manufacturing Technologies  phone:  +1 612 854 5300
7851 Metro Parkway                fax:    +1 612 854 6644
Minneapolis, MN 55425-1528 USA



Sun, 17 Aug 1997 06:40:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. One Scrollbar for two listboxes??

2. one scrollbar for two listboxes?

3. one scrollbar for two listboxes?

4. Scrolling two listboxes with one scrollbar?

5. Two canvas scrolled simultaneously by the same scrollbar (an UNIQUE scrollbar and TWO or more canvas)

6. help with scrolling two listboxes by the single scrollbar

7. Two canvases (widgets), one scrollbar..

8. Join several listboxes to one scrollbar...

9. Scrolling two different widgets will one scrollbar

10. How to use one scrollbar to control two text widgets

11. Synchronizing two text- widgets to one scrollbar ?

12. Multiple listbox control with one scrollbar

 

 
Powered by phpBB® Forum Software