How can I make the scrollbar work properly ???

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi all of you guys,

Actually Im trying to make a browser tab with scrollbar (because in my situation, there are many widgets in the browser tab so we dont have enough space for them), however I could not make it work properly...!!!

 

If anybody who know how to do it, please help me to solve the problem.

 

here I attached my code for your convenience

 

your help will be appreciated
Thanks
------------------------------------

# making tab in the browser
proc Make_TAB { } {
    
    lappend auto_path{<path to the folder containing hwt folder>}
    package require hwt; #to import the hwt package
       set tabName 'System_Parameters';
 
     hw browser delete $tabName;
    hw browser add $tabName end [ hw browser get frame $tabName ];
    hw browser select $tabName;

     set frm [ hw browser get frame $tabName ];
    
    set bclose [::hwt::CanvasButton $frm.bclose [::hwt::DluWidth 8] [ ::hwt::DluHeight 8 ] \
        icon  msclose  iconH   1  iconV   1  \
        relief  flat  help  'Exit Program'  takefocus 1 \
        command 'hw browser delete $tabName' ];
    pack $bclose -side top -anchor ne -padx 5 -pady 5 ;


#---- how can I make the scrollbar work properly ??? --------

 set scrb [scrollbar $frm.scrb -command '$frm yview']
 pack $scrb -side right -anchor nw;

#------------------------------------------------------------

    set labelWidth 27;
    set entryWidth 15;

    #section label
    set section1 [label $frm.section1 \
        -text 'SYSTEM PARAMETERS' \
        -justify left \
        -anchor nw \
        -font [hwt::AppFont]];
    pack $section1 -side top -anchor nw;

    hwt::AddPadding $frm -side top -height [hwt::DluHeight 5];

    # frame1
    set frame1 [frame $frm.frame1];
    pack $frame1 -side top -anchor nw;
    
    hwt::AddPadding $frame1 -side left -width [hwt::DluWidth 15];

    set entry11 [ hwt::AddEntry $frame1.entry11 \
        -label 'Mass (kg)' \
        -labelWidth $labelWidth \
        -entryWidth $entryWidth \
        -text '' \
        -textvariable mass_rocket \
        -validate real \
        -state normal \
        -withoutPacking];
    pack $entry11 -side top -anchor nw;
    set entry12 [ hwt::AddEntry $frame1.entry12 \
        -label 'Force (N)' \
        -labelWidth $labelWidth \
        -entryWidth $entryWidth \
        -text '' \
        -textvariable mass_b2 \
        -validate real \
        -state normal \
        -withoutPacking];
    pack $entry12 -side top -anchor nw;

    hwt::AddPadding $frame1 -side bottom -height [hwt::DluWidth 380];

    # buttons Load_Initial_Model, Run
    set btn1 [button $frm.btn1 -width 16 -height 2 -text {Load Initial Model} -command {Open_Model}];
    pack $btn1 -side left -padx 22 -pady 5 -anchor nw;

    set btn2 [button $frm.btn2 -width 16 -height 2 -text {Analysis Setting} -command {Analysis}];
    pack $btn2 -side left -padx 16 -pady 5 -anchor nw;


  }

# end proc Make_TAB

# main code
    set isFirst True;
    Make_TAB;
# end main code
---------------------------

Answers

  • tinh
    tinh Altair Community Member
    edited April 2013

    Hi

    Maybe we cannot scroll a frame

    Try using a textbox with scrollbar, and put your widgets on it

    using hwt::CheckScrollBars $textName $textWidth $textHeight to add scrollbars to the textbox

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2013

    Dear tinh,

    First Im greatly appreciated your kindness reply. Actually, I tried many times for making the textbox with scrollbar on the browser tab, however it still can not work properly ... here I attached my tcl code, if you dont mind please help me to add scrollbar so that it work properly.

    your help will be highly appreciated

    best regards

    MDD

     

    ------------------------------

    lappend auto_path{<path to the folder containing hwt folder>}
    package require hwt; #to import the hwt package
    set tabName 'System_Parameters';
     
    hw browser delete $tabName;
    hw browser add $tabName end [hw browser get frame $tabName];
    hw browser select $tabName;

    set frm [ hw browser get frame $tabName ];

    set bclose [::hwt::CanvasButton $frm.bclose [::hwt::DluWidth 8] [ ::hwt::DluHeight 8 ] \
        icon  msclose  iconH   1  iconV   1  \
        relief  flat  help  'Exit Program'  takefocus 1 \
        command 'hw browser delete $tabName' ];
    pack $bclose -side top -anchor ne -padx 5 -pady 5;

    # -----please help me to add scrollbar with the box-----------

    set box [hwt::AddCanvasBox $frm withbothScrolls]
    pack $box -anchor nw -fill both -expand 1 -padx 4 -pady 4;

    #-------------------------------------------------------------


    # buttons Load_Initial_Model, Run

    set btn1 [button $frm.btn1 -width 16 -height 2 -text {Load Initial Model} -command {Open_Model}];
    pack $btn1 -side left -padx 22 -pady 5 -anchor nw;

    set btn2 [button $frm.btn2 -width 16 -height 2 -text {Analysis Setting} -command {Analysis}];
    pack $btn2 -side left -padx 16 -pady 5 -anchor nw;
     

    ----------------------

  • tinh
    tinh Altair Community Member
    edited May 2013

    Hi, did you overcome the problem?

    try download bwidget package and put it in hw/tcl folder

    below is sample code

     

     

    #set up tab

    set tabname tinh

    set frmname .tinh

    destroy $frmname

    hm_framework removetab $tabname

    frame $frmname

    hm_framework addtab $tabname $frmname

    #set up scrollable frame

    set frmgrand [frame $frmname.frmgrand]

    set frmparent $frmgrand.frmparent

    package require BWidget

    ScrollableFrame $frmparent

    set frmscroll [$frmparent getframe]

    set hscroll [scrollbar $frmgrand.hscroll -orient h -command '$frmparent xview']

    set vscroll [scrollbar $frmgrand.vscroll -orient v -command '$frmparent yview']

    $frmparent configure -xscrollcommand '$hscroll set' -yscrollcommand '$vscroll set'

    #set up layout

    grid $frmparent $vscroll -row 0 -sticky news

    grid $frmparent $hscroll -col 0 -sticky news

    grid rowconfigure $frmparent 0 -weight 1

    grid columnconfigure $frmparent 0 -weight 1

    pack $frmgrand -anchor nw -fill both -expand 1

    bind $frmgrand <Configure> '$frmparent configure -width \[expr %w - \[winfo width $vscroll\]\] \

    -height \[expr %h - \[winfo height $hscroll\]\]'

     

    #just for test

    for {set i 0} {$i < 10} {incr i} {

    set frm$i [frame $frmscroll.frmtest$i]

    pack [set frm$i] -side left -anchor nw

    for {set j 0} {$j < 50} {incr j} {

    set btn$j [button [set frm$i].btn$j -text Button$i$j]

    pack [set btn$j] -side top -anchor nw

    }

    }
  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2013

    Dear tinh,

     

    by following your code & advices, finally my problem has solved.

     

    Im greatly appreciated your kindness help, especially spending your time and effort for making the demo script.

     

    again, thanks you very much for your kindness help.

     

    best regards

    Mai Duc Dai