0
votes

is there a way to retrieve a tree structure of a GUI layout from a tcl/tk application? I am trying to retrieve a screen layout so that I would convert this to an html/electron application.

Any suggestions would be nice.

1

1 Answers

0
votes

The basic structure of the widget hierarchy can be obtained by using winfo children and basic recursion:

proc dumpStructure {{w .} {indent ""}} {
    puts "$indent[winfo class $w] $w"
    foreach configItem [$w configure] {
        lassign $configItem name - - def value
        if {$def ne $value && $name ne "-command"} {
            # Note: we've excluded things that are set to the default and
            # also the -command callbacks because they usually look messy
            puts "$indent    $name $value"
        }
    }
    foreach child [winfo children $w] {
        dumpStructure $child "$indent  "
    }
}

Notice how you can use each widget's configure method to get all the information about how it is set up, except that text and canvas widgets are a lot more complex. (You'll probably need to redevelop those if you can't find an acceptable alternative.) The geometry management configuration is trickier, as geometry managers don't have quite so much common code (and text and canvas are special in that regard, but so are a few others).

Menus are their own special case, but probably map fairly easily in practice.