How to create vertical scroll bar for window

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

hello everyone I have created a window using  hwt::CreateWindow win

 

I have added only one row now to reduce size of Quote. Number of rows in actual script are in loop so my number of rows sometimes exceeds 100. So I need scroll to window.

 

So how can I add scroll to it

 

And I seardched for  hwt::CreateWindow win help for all pther commands help is easily available in HM  help but I didnt find any help related to these commands, So anybody direct me to proper help for hwt commands and specifically  hwt::CreateWindow win

 

proc ::compQuery::window {} {
    variable str_slave;
    variable str_master1 '';
    variable str_master2 '';
    variable str_master3 '';
    variable str_master4 '';
    variable str_master5 '';
    variable str_master6 '';
    variable str_master7 '';
    variable str_master8 '';
    variable e1; 
    variable e2;
    variable l1; 
    variable l2;
    variable e3;
    variable l3; 
    variable e4;
    variable l4; 
    variable e5;
    variable l5;
    variable e6;
    variable l6;
    variable e7;
    variable l7;
    variable e8;
    variable l8;
    variable ang_incr;
    variable def_val;

 

    set dlgWidth  [ hwt::DluWidth 100 [ hwt::AppFont ]];
    set dlgHeight [ hwt::DluHeight  250 [ hwt::AppFont ]];

    set min_dlgWidth  [ hwt::DluWidth  250 [ hwt::AppFont ]];
    set min_dlgHeight [ hwt::DluHeight  200 [ hwt::AppFont ]];

    hwt::CreateWindow win \
        -minsize 200 100\
        -maxsize 2000 2000 \
        -noGeometrySaving \
        -geometry ${dlgWidth}x${dlgHeight} \
        -cancelButton Cancel \
        -defaultButton Cancel \
        -acceptButton Accept \
        -minSize $min_dlgWidth $min_dlgHeight \
        -acceptFunc '::compQuery::GetcompVar' \
        -cancelFunc '::compQuery::Cancel_func' \
        -windowtitle 'Stress contour capture script' \
        -post;

    #Create recess to hold frames
    set recess [hwt::WindowRecess win];
        

    grid columnconfigure $recess 1 -weight 1 ;

    set l1 [::hwtk::label $recess.l1 -text 'Evaluation criteria for Max principal stress:']
    set e1 [::hwtk::entry $recess.e1 -width 200 -takefocus 1 -help 'Entered value is max limit above this shown as grey colour' -textvariable  ::compQuery::str_master1];
    grid $l1 -row 1 -col 0 -sticky w -padx 4 -pady 4;
    grid $e1 -row 1 -col 1 -sticky e -padx 4 -pady 4;
    #default value $recess.e1 set 315;

  
    hwt::KeepOnTop win
   }

Answers

  • tinh
    tinh Altair Community Member
    edited June 2017

    Hi

    There is no option to scroll a toplevel

    You have to use text box or canvas widget to do it

    Another way, use package BWidget which has tk classes to create scrollable frame and toplevel

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2017

    Hello tinh

    do you have any example for these suggested method and which one will be best to use in current case

  • tinh
    tinh Altair Community Member
    edited June 2017

    Hi

    This is usage of bwidget scrollable frame

     

    http://wiki.tcl.tk/1091

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2017

    Hello, 

    I studied some help on web now I am able to get scroll bar but not able to fix content in  between scroll bar

     

    Now I am doing trial and error to get final out come

     

    mean while can anybody look at my script and suggest improvement

    namespace eval ::compQuery {
    variable str_master1 '';
        variable str_master2 '';
        variable str_master3 '';
        variable str_master4 '';
        variable str_master5 '';
        variable str_master6 '';
        variable str_master7 '';
        variable str_master8 '';
        variable ang_incr;
        variable def_val;
    }


    proc ::compQuery::window {} {
        variable str_slave;
        variable str_master1 '';
        variable str_master2 '';
        variable str_master3 '';
        variable str_master4 '';
        variable str_master5 '';
        variable str_master6 '';
        variable str_master7 '';
        variable str_master8 '';
        variable e1; 
        variable e2;
        variable k1; 
        variable k2;
        variable k3; 
        variable k4;
        variable k5; 
        variable k6;
        variable l1; 
        variable l2;
        variable e3;
        variable l3; 
        variable e4;
        variable l4; 
        variable e5;
        variable l5;
        variable e6;
        variable l6;
        variable e7;
        variable l7;
        variable e8;
        variable l8;
        variable ang_incr;
        variable def_val;

        set dlgWidth  [ hwt::DluWidth 100 [ hwt::AppFont ]];
        set dlgHeight [ hwt::DluHeight  250 [ hwt::AppFont ]];

        set min_dlgWidth  [ hwt::DluWidth  250 [ hwt::AppFont ]];
        set min_dlgHeight [ hwt::DluHeight  200 [ hwt::AppFont ]];

        hwt::CreateWindow win \
            -minsize 200 100\
            -maxsize 1000 100 \
            -noGeometrySaving \
            -geometry ${dlgWidth}x${dlgHeight} \
            -cancelButton Cancel \
            -defaultButton Cancel \
            -acceptButton Accept \
            -minSize $min_dlgWidth $min_dlgHeight \
            -acceptFunc '::compQuery::GetcompVar' \
            -cancelFunc '::compQuery::Cancel_func' \
            -windowtitle 'Stress contour capture script' \
            -post;

        #Create recess to hold frames
        set recess [hwt::WindowRecess win];
        
        set types {
            {{H3D File}      {'.h3d' }        }
            {{OP2 File}      {'.op2' }        }
            {{All Files}             * }
        }    

        grid columnconfigure $recess 1 -weight 1 ;
        
        set z [tk::listbox $recess.z -yscrollcommand '.ss set' -xscrollcommand '.s set' -height 5 -width 20]
        set y [ttk::scrollbar $recess.ss -command '.y$ yview' -orient vertical ]
        set x [ttk::scrollbar $recess.s -command '.x xview' -orient horizontal ]
        grid [set z] -column 0 -row 0 -sticky nwes;
        grid [set y] -column 1 -row 0 -sticky ns;
        grid [set x] -column 0 -row 1 -sticky ew
         
         for {set j 1} {$j <= 4 } {incr j} {
         
        insert end set l$j [::hwtk::label $recess.l$j -text 'Evaluation criteria for Max principal stress:']
        insert end set e$j [::hwtk::entry $recess.e$j -width 200 -takefocus 1 -help 'Entered value is max limit above this shown as grey colour' -textvariable  ::compQuery::str_master1];
        insert end set k$j [::hwtk::label $recess.k$j -text '****']
        
        $recess.z grid [set l$j] -row $j -col 0 -sticky w -padx 4 -pady 4;
        $recess.z grid [set e$j] -row $j -col 1 -sticky e -padx 4 -pady 4;
        $recess.z grid [set k$j] -row $j -col 2 -sticky e -padx 4 -pady 4;

        #default value $recess.e1 set 315;
        }
        hwt::KeepOnTop win
        
        
    }

    proc ::compQuery::Cancel_func {args} {
             catch {destroy .win};
    }

    ::compQuery::window
     

     

  • tinh
    tinh Altair Community Member
    edited June 2017

    Hi,

    This is a sample using textbox as scrollable window, that you don't need to care about scrollbars

     set w .myToplevelWindow ::hwtk::toplevel $w -title 'Sample scrollable window' pack [::hwtk::text $w.t -width 80 -height 25] -side top -fill both -expand 1 pack [::hwtk::frame $w.f] -side top -fill x pack [::hwtk::button $w.f.btnCancel -text Cancel -command ::p_btnCancel_Invoke] -side right -anchor e pack [::hwtk::button $w.f.btnOK -text OK -command ::p_btnOK_Invoke] -side right -anchor e set f $w.t.text.f $w.t.text window create end -window [::hwtk::frame $f] for {set i 0} {$i<100} {incr i} {     set lbl [::hwtk::label $f.lbl$i -text 'label [expr 1+$i]']     set ent [::hwtk::entry $f.ent$i -width 20]     grid $lbl $ent -row $i }

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2017

    Hello tinh,

    I am running your script in HM 12.

     

    Received following error

    Error : Unknown option '-title'

     

  • tinh
    tinh Altair Community Member
    edited June 2017

    Please upgrade to hm13 or 14 or 15

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2017

    ohhh.....ok

     

    Thank you

     

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited October 2018

    Hi,

    This is a sample using textbox as scrollable window, that you don't need to care about scrollbars

      set w .myToplevelWindow ::hwtk::toplevel $w -title 'Sample scrollable window' pack [::hwtk::text $w.t -width 80 -height 25] -side top -fill both -expand 1 pack [::hwtk::frame $w.f] -side top -fill x pack [::hwtk::button $w.f.btnCancel -text Cancel -command ::p_btnCancel_Invoke] -side right -anchor e pack [::hwtk::button $w.f.btnOK -text OK -command ::p_btnOK_Invoke] -side right -anchor e set f $w.t.text.f $w.t.text window create end -window [::hwtk::frame $f] for {set i 0} {$i<100} {incr i} {     set lbl [::hwtk::label $f.lbl$i -text 'label [expr 1+$i]']     set ent [::hwtk::entry $f.ent$i -width 20]     grid $lbl $ent -row $i }

     

    Can you modify this, so i create a  subframe inside which is scrollable. @tinh

  • tinh
    tinh Altair Community Member
    edited October 2018

    I think above sample is very clear,

    Frame 'f' was scrollable and you can pack anything in it

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited October 2018

    @tinh i have list of check box inside the frame. I have to make it scrollable.

  • tinh
    tinh Altair Community Member
    edited October 2018

    Put that frame in text widget like above sample