Posted to tcl by Stu at Thu Jul 20 12:58:45 GMT 2023view pretty
$ cat incomp.tcl #! /bin/sh # \ exec tclsh${TCL} "$0" "$@" proc createGui {w compact} { set code [gub " # A row of labels over a row of entries # Use row/column adjustments to turn it # into a vertical stack of widgets. # This is understandable when working it out # but I'm not sure it can be easily understood # just by reading it. ;L L L L ;# Four labels. ;E E E E ;# Four entries. ;Li ;# Another lable to show info. :Li -columnspan 4 ;# Grid it to span all the columns. .{L} -text a b c d ;# Give the labels some text. # The power of Tcl! [expr {$compact ? { !:-L1-3 +2 ;# Move labels L1-3 down by 2 rows ;# relative to what would be their rows. !:-E0 -6 ;# This pushes E0 down by 6 rows ;# so it has to be pulled back up. !:-E1-3 +2 ;# Entries E1-3 have to be pushed ;# down like with L1-3. !:|L1-3,E1-3 -1 ;# Pull back the columns for the widget by 1. ;# This will put them all in column 0. .Li -text Compact } : { .Li -text Normal }}] " $w] eval $code puts $code puts "" } package require gub namespace import ::gub::gub package require Tk toplevel .q createGui . no createGui .q yes # EOF $ ./incomp.tcl grid [ttk::label .l0 -text a] -row 0 -column 0 grid [ttk::label .l1 -text b] -row 0 -column 1 grid [ttk::label .l2 -text c] -row 0 -column 2 grid [ttk::label .l3 -text d] -row 0 -column 3 grid [ttk::entry .e0] -row 1 -column 0 grid [ttk::entry .e1] -row 1 -column 1 grid [ttk::entry .e2] -row 1 -column 2 grid [ttk::entry .e3] -row 1 -column 3 grid [ttk::label .l4 -text Normal] -columnspan 4 -row 2 -column 0 grid [ttk::label .q.l0 -text a] -row 0 -column 0 grid [ttk::label .q.l1 -text b] -row 2 -column 0 grid [ttk::label .q.l2 -text c] -row 4 -column 0 grid [ttk::label .q.l3 -text d] -row 6 -column 0 grid [ttk::entry .q.e0] -row 1 -column 0 grid [ttk::entry .q.e1] -row 3 -column 0 grid [ttk::entry .q.e2] -row 5 -column 0 grid [ttk::entry .q.e3] -row 7 -column 0 grid [ttk::label .q.l4 -text Compact] -columnspan 4 -row 8 -column 0