tags:

views:

102

answers:

1

Hi, Is there way to disable all widget in tk window with single proc? argument can be just initial toplevel path.

+1  A: 

Given a widget, you can get all of the children of that widget with [winfo children]. With a tiny recursive procedure you can act upon every widget in a tree of widgets. If you want to be lazy, you can usually also get a list of all widgets by doing [info commands .*]. That is often Good Enough, unless your application creates procedures or images that begin with ".".

Most tk widgets accept a "-state" option, and those that don't can usually be ignored since state doesn't matter (for example, a frame widget). So, you can iterate over all the widgets and do something like [catch {$widget configure -state disabled}]. This won't work if you have unusual widgets that need to be enabled or disabled by some other means (such as the ttk button which has a "state" subcommand).

If you have a simple application using standard widgets, something like this may be Good Enough:

proc disable_all {path} {
    catch {$path configure -state disabled}
    foreach child [winfo children $path] {
        disable_all $child
    }
}

For precise control you can use "[winfo class $widget]" to get the class of the widget, and do different commands depending on the class.

Bryan Oakley
in tcl recursion proc is it possible to save previous state of widget? So next time I can enable only which are disabled.
OliveOne
I was thinking to useproc walkIntoTKTree {w} { set depth 0 while {$depth < [llength [winfo children $w]]} { walkIntoTKTree [lindex [winfo children $w] $depth] incr depth; } puts "w=$w"}but ur soln is better
OliveOne