Tk Source Code

Artifact [c4361937]
Login

Artifact c436193755ffa229eefa43e6701449be782c8d3443b125231de016f0b35e4fc3:

Attachment "scrolltest.tcl" to ticket [cde766f9] added by nemethi 2021-03-18 14:45:32.
package require Tk

set font {TkTextFont 18}
ttk::style configure Treeview -font $font \
    -rowheight [expr {[font metrics $font -linespace] + 3}]

set f [ttk::frame .f]
set tbl $f.tbl
set hsb $f.hsb
set vsb $f.vsb

set colIdList {col0 col1 col2 col3 col4 col5 col6 col7 col8 col9}
ttk::treeview $tbl -columns $colIdList \
    -height 10 -show headings -selectmode browse \
    -xscrollcommand [list $hsb set] -yscrollcommand [list $vsb set]
ttk::scrollbar $hsb -orient horizontal -command [list $tbl xview]
ttk::scrollbar $vsb -orient vertical   -command [list $tbl yview]

foreach colId $colIdList {
    set col [string index $colId end]
    $tbl heading $colId -text "Column $col" -anchor center
    $tbl column $colId -anchor center -minwidth 85 -width 85 -stretch true
}

$f configure -borderwidth 1 -relief solid

grid $tbl -row 0 -column 0 -sticky news
grid $vsb -row 0 -column 1 -sticky ns
grid $hsb -row 1 -column 0 -sticky ew
grid rowconfigure    $f 0 -weight 1
grid columnconfigure $f 0 -weight 1

set row 0
proc addRow {} {
    global tbl row
    set values {}
    for {set col 0} {$col < 10} {incr col} {
	lappend values "cell $row,$col"
    }
    $tbl insert {} end -values $values
    incr row
}

set b [ttk::button .b -text "Add Row to Table" -command addRow]

grid $b -sticky news -padx 10
grid $f -sticky news -padx 10 -pady 10
grid rowconfigure    . 1 -weight 1
grid columnconfigure . 0 -weight 1
wm geometry . 716x334

for {set n 0} {$n < 100} {incr n} {
    addRow
}