# Create a toplevel window for displaying a bunch of
# checkbuttons. We'll display this on demand from the
# main window.
toplevel .dialog
canvas .dialog.c -height 100 -width 50 -yscrollcommand {.dialog.sb set}
scrollbar .dialog.sb -orient vertical -command {.dialog.c yview}
# Create our frame to hold all of our checkbuttons
frame .dialog.c.buttons
# Create a bunch of checkbuttons and pack them into the frame
for {set i 1} {$i <=10 } {incr i} {
checkbutton .dialog.c.buttons.$i -text "$i" -variable c($i)
pack .dialog.c.buttons.$i -anchor w -padx 2 -pady 1
}
# Tell the canvas to display the frame, anchoring the
# upper-left hand corner of the frame in the upper-left
# hand corner of the canvas
.dialog.c create window 0 0 -anchor nw -window .dialog.c.buttons
button .dialog.close -text "Close window" -command {
wm withdraw .dialog
}
# Use grid to display the canvas, the scrollbar, and the
# close button in the toplevel window. Handle resizing properly.
grid .dialog.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid .dialog.sb -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid .dialog.close -row 1 -column 0 -columnspan 2 -pady 2
grid columnconfigure .dialog 0 -weight 1
grid rowconfigure .dialog 0 -weight 1
# Detect <Configure> events on the frame to detect when
# it is first displayed and any time is is resized.
# In either case, recompute the visible bounds of the
# canvas and update its -scrollregion attribute.
bind .dialog.c.buttons <Configure> {
.dialog.c configure -scrollregion [.dialog.c bbox all]
}
# Finish the setup of the toplevel dialog window
wm title .dialog "Checkbuttons Galore!"
wm withdraw .dialog
# Create our main window interface
button .popup -text "Settings..." -command {
wm deiconify .dialog
}
button .exit -text "Quit" -command { exit }
pack .popup .exit -padx 4 -pady 4