Question

I was having a look at the Tk demo widget 8.5/8.6 and found the line inside:

eval destroy [winfo child .]

When I looked up winfo, there was no child option, but there was a children option. I tested a few things with the two and they appear to be the same.

% package require Tk
% pack [label .m1 -text "Hello"]
% pack [label .m2 -text "World"]
% puts [winfo child .]
.m1 .m2
% puts [winfo children .]
.m1 .m2

Those two seem to be the same to me, but one is documented and the other isn't. Is there any difference or is that only a consequence of different versions of Tcl (it seems that child was used earlier and is now being replaced with children -perhaps because of a bug?-, although both behave roughly similarly)?

If they are different, is there any reason why someone would use one instead of the other?

Was it helpful?

Solution

Tcl allows you to abbreviate any command to the closest non-ambiguous substring. For instance:

% string range abcd 0 2
abc
% stri ran abcd 0 2
abc
% str r abcd 0 2
unknown or ambiguous subcommand "r": must be bytelength, compare, equal, first, index, is,  last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart
% 

The final line has an ambiguous match - r can match any of range, repeat, replace or reverse so we get an error raised. ra is the shortest match possible for range here.

The specific documentation applicable to this is actually in the man page for Tcl_GetIndexFromObj where is states

A match occurs if objPtr's string value is identical to one of the strings in tablePtr, or if it is a non-empty unique abbreviation for exactly one of the strings in tablePtr and the TCL_EXACT flag was not specified

This is because the Tcl_GetIndexFromObj API call is typically how commands and subcommands are identified throughout the Tcl sources.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top