Option sources and geometry
ztk::debug why answers the question "why does this widget have this value". It gives the call that set each option, with its line and its stack. ztk::debug geometry gives the chain of containers that sets the size and the place of a widget. ztk::debug explain gives the same facts as short lines. Debug a form uses these commands on a live form with three bugs.
The source of an option
ztk::debug sources on starts the record of option sources. Turn it on before the code that you want to check, for example on the first line of the script. While it is off, a configure call keeps no record, and its cost is one test of a flag.
ztk::debug sources on
button .ok -text Save
pack .ok
proc lock {w} {
$w configure -state disabled
}
lock .ok
puts [ztk::debug why .ok -state]
The output is one dict:
option -state value disabled source configure code {$w configure -state disabled} call {.ok configure -state disabled} file app.tcl line 2 fileline 14 proc lock prev normal count 1 seq 3 stack {{lock .ok}}
| Key | What it has |
|---|---|
option, value |
The option and the value that cget gives. |
source |
create, configure, animate (a step of ztk::animate), internal (the widget keeps the option equal to its state), optiondb (the new widget took the value of the option database, option add), variable (the -text of a -textvariable), call (a call set it while the record was off), style (cget reads the computed style), or default. |
code |
The source text of the command, before substitution. |
call |
The words of the call with their values. |
file, line |
The value of info script, and the line of the command in its own script. For a command in a proc, the line counts from the start of the body of the proc. |
fileline |
The line of the command in file, also for a command in a proc or in the body of an if or a loop. file is then the file of the command. It is 0 for a command from a string that ztk did not run as a file, such as eval $text. The main script and the code of a live snippet get it. |
proc, stack |
The innermost proc, and the words of each proc call, innermost first. A call at the global level has an empty stack. |
prev |
The value before the call. |
count, seq |
The count of recorded writes of the option, and the order of the last write among all recorded writes. |
default |
The default value, for the source default. |
style |
For an option that no call set: the CSS declaration that gives the look, with its sheet, its origin, and its line. |
overrides |
For an option that a call set: the CSS declaration that the option overrides. |
variable |
The name of the -textvariable. |
An option with a CSS property is -background, -foreground, -borderwidth, -relief, -font, -padx, -pady, -padding, -cursor, or -insertbackground. For a property that inherits, such as color, the declaration can be on an ancestor. Then the dict has the key inherited with the path of that ancestor.
ztk::debug why .ok with no option gives a list of these dicts: one for each option that a call set or that the style gives. Add -all for each option of the widget.
A value from the option database (option add, option readfile) has the source optiondb.
The geometry chain
ztk::debug geometry path runs the pending layout, and then gives one dict for the widget and one for each container up to its toplevel.
frame .f -width 100 -height 40
pack propagate .f 0
pack .f
button .f.ok -text "A long label"
pack .f.ok
puts [lindex [ztk::debug geometry .f.ok] 0]
| Key | What it has |
|---|---|
widget, class |
The path and the class. |
req |
The requested width and height in logical pixels. |
box |
The x, y, width, and height in the container. |
mapped |
1 when the widget is mapped. |
size |
The -width and -height that a call set. |
manager, info |
The geometry manager and the result of its info subcommand. An empty manager means that no manager has the widget. |
propagate |
For a container: 1 when its content sets its requested size. |
notes |
Each difference between the requested size and the box, and the reason that a widget is not mapped. |
Cost
A script with 200,000 calls of .b configure -text $i -state normal ran 1,161,719,315 instructions before ztk::debug existed, 1,165,918,947 with the record off (0.36 % more, 21 instructions for each call), and 2,211,793,540 with the record on. The command was perf stat -e instructions:u -r 3 ztk --headless --allow clock bench/debug-configure.tcl on a ReleaseFast build, on 2026-11-26, on an Intel Core i7-6700K with Linux. The difference in time with the record off was smaller than the spread between runs.
Limits
- The line of a command in a proc counts from the body of the proc. The file of the proc and the line in that file need the debug interface of ztcl.
- The record keeps only the last write of each option. The trace has each write.