Search code examples
tcltk-toolkit

How to add a scroll bar?


I have this procedure that creates a window that displays a list of scenarios to be executed. A list is displayed with four buttons (check all, uncheck all, ok, annuler) and we are able to check items in the list. The problem I have with this window is that there is no scroll bar, neither in x, nor in y.

It means that if the names of the scenarios are too long, we can't see the complete text nor see the square to check. Also if the number of scenarios is too high, we can't see the complete list in the window.

Do you know if it is easy to add a scrollbar in x and y for this window?

Here is the window:

enter image description here

Here is the code :

set dlg [Dialog .new -anchor n -place center -side right -cancel 6 -default 0 -parent . -modal local \
     -transient 0]
# place this button first because it is default value (-default 0)
$dlg add -text "check all" -underline 2 -command {run_simu_check_all}
$dlg add -text "uncheck all" -underline 2 -command {run_simu_uncheck_all}
# when "ok" is hit, windows is closed and tests are run (another windows will be open)
$dlg add -text "OK" -underline 2 -command {.new enddialog "";pexecute_simu_script $Cockpit::bf}

# this button is placed in last place because it is the choosen value (-cancel 5) if we cancel (esc key)
$dlg add -text "  Annuler  " -underline 2 -command {.new enddialog ""}

set frame [frame [$dlg getframe].frame]
    set label [label $frame.label]
    pack $label -side top -anchor n -fill x -expand 1
pack $frame -fill both -expand 1

# checkbox display for each scenario 
set liste_entite [liste_entite $Cockpit::bf fic_simu_modtb_comp]
foreach entite $liste_entite {
    if {$entite != "NONE"} {
        global ${entite}_var
        if {![info exists ${entite}_var]} {set ${entite}_var 0}
        # we use -side top so that checkbutton be in column from up to down
        pack [checkbutton $frame.$entite \
                    -text "$entite" \
                    -font {arial 8} \
                    -width 50\
                    -justify left \
                    -variable ${entite}_var \
                    -command {} \
                   ] -side top
    }
}

.new configure -title "choose scenario to run"
[.new getframe].frame.label configure -text "select scenario to run"

wm iconbitmap .new $Cockpit::icon
.new draw

Solution

  • at the end, I use a scrolledframe using bwidget and I was able to add scrollbar inside my dialogbox.