Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  How can I create a scrollable window of buttons?
 The easy way to do this is to make the buttons the children of a
`canvas` widget, place them in the canvas with `canvas create window
...` and attach a `scrollbar` to the canvas.  For example:

scrollbar .sy -orient v -command ".c yview"
canvas .c -yscrollcommand ".sy set"
pack .sy -fill y -side right
pack .c -fill both -expand 1 -side left
set x 2
set y 2
for {set i 0} {$i<20} {incr i} {
    button .c.b$i -text [list Button $i] -width 10 -command [list puts "$i pressed"]
    .c create window $x $y -window .c.b$i -anchor nw
    incr y [winfo reqheight .c.b$i]
.c configure -scrollregion [list 0 0 [winfo reqwidth .c.b0] $y]  -width [winfo reqwidth .c.b0]