Previous: Using TCL code to generate widgets
Up: Widgets
Next: Data entry example
Previous Page: Using TCL code to generate widgets
Next Page: Data entry example
TCL code fragments can be useful for avoiding the need to specify a large number of widgets explicitly, as in the calendar example in the previous section. However, it is almost certainly better to make such code fragments into TCL procedures, as shown:
proc makecalendar {daysinmonth} {
for {set i 1} {$i <= $daysinmonth} {incr i 1} {
button .button$i -width 16 -text "$i" -command "daydetails $i"
pack .button$i
}
}
Note that this does not cause the code to be executed, but simply defines a procedure for generating the required widgets. To generate a button array for a 31 day month, the command
makecalendar 31
should be used, after the procedure has been defined.