[HJG] 2014-03-26 - Demo: grid of 1000 buttons. ====== # http://wiki.tcl.tk/39622 # gridDemo-grid3a.tcl package require Tk global Prg set Prg(Title) "Grid-Demo_BigGrid" set Prg(Version) "v0.04" set Prg(Date) "2014-03-26" set Prg(Author) "Hans-Joachim Gurt" set Prg(Contact) [string map -nocase {: @ ! .} gurt:gmx!de] set Prg(About) "Grid-Demo - BigGrid" set Prg(Msg) "big grid, with lots of buttons" proc Start {} { set ::Prg(Msg) "Starting..." after 1000 { .b_a1 invoke } ;# Sorry, no animated button-press here... after 1500 { .b_b2 invoke } after 2000 { .b_c3 invoke } after 2500 { .b_c3 invoke } } proc ButtonProc { b } { set c [ .b_$b cget -bg ] ;# SystemButtonFace set ::Prg(Msg) "Button pressed: $b ($c)" if { $c=="red" } { set c2 cyan } else { set c2 red } .b_$b configure -bg $c2 } #: Main wm title . "$Prg(Title) $Prg(Version)" puts "$Prg(Title) $Prg(Version)" label .lb_1 -text "GridDemo" -width 12 -bg white -pady 10 label .lb_2 -textvariable Prg(Msg) -bg grey -pady 10 grid .lb_1 option add *Button.width 2 ;# "m10", "w10" etc. look a bit cramped # option add *Button.height 2 ## button .b_11 -text "11" -command { ButtonProc "11" } set n 0 set maxCol 40 # set maxRow 20 # for {set r 1} {$r<=$maxRow} {incr r} { foreach r { a b c d e f g h i j k m n o p q r s t u v w x y z } { set xb "grid " for {set c 1} {$c<=$maxCol} {incr c} { button .b_$r$c -text "$r$c" -command "ButtonProc $r$c" append xb ".b_$r$c " ;# collect buttons incr n 1 } append xb "-sticky nsew" ;# create a grid-row, e.g.: eval $xb ;# grid .b_11 .b_12 .b_13 .b_14 -sticky nsew } set ::Prg(Msg) "Buttons created: $n" grid .lb_2 -sticky ew option add *Button.width 7 option add *Button.height 1 button .bt_start -text "Start" -command { Start } button .bt_quit -text "Quit" -command { exit } ;# ?? place buttons in specific location ?? grid .bt_start - .bt_quit grid configure .lb_1 -columnspan $maxCol -padx 4 grid configure .lb_2 -columnspan $maxCol -padx 4 grid configure .bt_start -columnspan 6 -padx 4 -sticky w grid configure .bt_quit -columnspan 6 -padx 4 -sticky e #. ====== <>Example | GUI