Updated 2015-05-20 16:27:40 by HJG

HJG 2014-03-26 - This belongs to the series of Grid-Demos: a really big grid of 1000 buttons.
# http://wiki.tcl.tk/39622
# gridDemo-grid3b.tcl

  package require Tk

  global Prg
  set Prg(Title)    "Grid-Demo_BigGrid"
  set Prg(Version)  "v0.06"
  set Prg(Date)     "2014-03-28"
  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 sleep {N} {
      after [expr {int($N * 1000)}]
  }

  proc Start {} {
      set ::Prg(Msg)  "Starting..."
      after 1000  { .b_a1 invoke; }
      after 1500  { .b_b2 invoke; }
      after 2000  { .b_c3 invoke; }
      after 2500  { .b_c3 invoke; }
      after 3500  set ::Prg(Msg)  "Done."
  }

  proc Hello {} {
      set ::Prg(Msg)  "Hello..."
      set d 1000
      foreach bt { d4 e4 f4 g4 h4  f5 f6  d7 e7 f7 g7 h7 
                   d9 d10 d11 d12  e9  f9 f10 f11  g9  h9 h10 h11 h12
                   d14 e14 f14 g14 h14  h15 h16 h17
                   d19 e19 f19 g19 h19  h20 h21 h22
                   d24 d25 d26 d27  e24 e27  f24 f27  g24 g27  h24 h25 h26 h27
                   d30 d31  e30 e31  f30 f31  h30 h31} {
        incr d 100
        after $d  .b_$bt invoke;  
      }
    # sleep 1; 
    # set ::Prg(Msg) "Done !" 
    incr d 1000
    after $d [ list set ::Prg(Msg) "Done !" ]
  }
  
  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 nB 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} {
            incr nB 1
            button     .b_$r$c -text "$r$c" -command "ButtonProc $r$c"
            append xb ".b_$r$c "   ;# collect buttons
        }
        append xb "-sticky nsew" ;# create a complete row of the grid, e.g.:
        eval $xb                 ;#  grid .b_a1 .b_a2 .b_a3 .b_a4 -sticky nsew
    }
    set ::Prg(Msg)  "Buttons created: $nB"

    grid .lb_2             -sticky ew

    option add *Button.width  7
    option add *Button.height 1
    button .bt_start -text "Start" -command { Start }
    button .bt_hello -text "Hello" -command { Hello }
    button .bt_quit  -text "Quit"  -command { exit  }

    ;# ?? place buttons in specific location ??
    grid .bt_start - - .bt_hello - - .bt_quit

    grid configure .lb_1     -columnspan $maxCol -padx 4
    grid configure .lb_2     -columnspan $maxCol -padx 4

    grid configure .bt_start -columnspan 4 -padx 4
    grid configure .bt_hello -columnspan 4 -padx 4 
    grid configure .bt_quit  -columnspan 4 -padx 4 -sticky e

    focus -force .bt_start

#.

See also: