Drive a window: tree and inject
ztk::tree gives each widget with its class, its box, and its map state. ztk::inject sends a pointer, wheel, key, or text event through the hit test and the focus, as a real backend does. Together they click a widget as a person does, so a script or an agent finds a bug of input with no display.
The bug: a button that does nothing
The counter of examples/debug/dead-button.tcl has a button Add. A click on Add does not change the count.

The script clicks the center of Add with ztk::inject, and the trace records the events:
foreach row [ztk::tree .] {
lassign $row path class x y w h mapped
if {$path eq ".add"} { set cx [expr {$x + $w / 2}]; set cy [expr {$y + $h / 2}] }
}
ztk::debug trace start -kinds {event command}
ztk::inject . motion $cx $cy
ztk::inject . press 1 $cx $cy
ztk::inject . release 1 $cx $cy
update
puts "count $count"
foreach r [ztk::debug trace records] {
set what [dict getdef $r event [dict getdef $r script {}]]
puts "[dict get $r kind] [dict get $r widget] $what"
}
Then it lists each mapped widget whose box has the point of the click, from ztk::tree. ztk --headless examples/debug/dead-button.tcl prints:
count 0
event .banner <Button-1>
event .banner <ButtonRelease-1>
at 45,72: . Ztk 0 0 91 96
at 45,72: .add Button 20 57 51 31
at 45,72: .banner Frame 0 68 91 28
The press and the release went to .banner, so the -command of Add did not run. The tree gives the reason: the box of .banner covers the point 45,72, the center of Add. The script made .banner after .add, so .banner is above .add in the stacking order, and it gets the click.
The fix
Make the banner lower, or put it in its own row of the layout. With the argument fix, the script gives the banner a height of 6:
place configure .banner -height 6
The same clicks now give:
count 1
event .add <Button-1>
event .add <FocusIn>
event .add <ButtonRelease-1>
command .add incr count
event .n <Configure>
at 45,72: . Ztk 0 0 91 96
at 45,72: .add Button 20 57 51 31
The commands
| Command | Description |
|---|---|
ztk::tree ?path? |
A list with one item for each widget: {PATH CLASS X Y WIDTH HEIGHT MAPPED}, in logical pixels of the toplevel (reference). |
ztk::inject . motion X Y, press B X Y, release B X Y |
A pointer event at a point of the toplevel (reference). |
ztk::inject . key KEYSYM, text STRING |
A key or text into the widget with the focus. |
ztk::debug click path |
Clicks the center of a widget and gives each event with its bindings, commands, and option changes as lines (Traces). |
ztk::snapshot path |
A PNG of a widget as base64 text (reference). |
ztk::debug click .add clicks the center of Add too. In the bug case, its answer has only the frame that drew .banner again. The trace with -kinds event shows the widget that got the events.
tests/debug-examples.sh runs this example with and without the fix and checks these lines.