Question

Reading this entry in the Tcl/Tk online reference i came across this paragraph where it states:

The combobox widget also supports the following ttk::entry widget subcommands (see ttk::entry(n) for details):

  • bbox
  • delete
  • icursor
  • index
  • insert
  • selection
  • xview

I know in this case of the Combobox widget it's comprised partially of an Entry widget but how exactly are subcommands used?

Was it helpful?

Solution

This is the common Tk command structure, and you'll need it to interact with any Tk widget. A subcommand of a widget is done by using the pathname of the object as the base command, then the subcommand you want. E.g.,

ttk::combobox .cb
.cb insert 0 "my text"

OTHER TIPS

The obvious answer is, like this: pathname subcommand ?arg...?, i.e. you begin the invocation with the pathname to the widget (which is the name of a command which was generated when you created the widget), then the subcommand, then any arguments.

I'm not sure if that's what you're asking about, however. Am I missing something?

Subcommands are very much like methods of an object system; with those examples in Tk, you give the name of the object (the widget) as one argument, the name of the method (the subcommand) as the next argument, and any further arguments that are required after that.

If you follow the link on that manual page, it will take you to the exact description of how to use them. For example, it says that the index subcommand is exactly as is supported by the ttk::entry widget, and going to that page you see:

pathName index index
          Returns the numerical index corresponding to index.

The definition of index is further up the page (and could be better cross-referenced, I accept).

INDICES

Many of the entry widget commands take one or more indices as arguments. An index specifies a particular character in the entry's string, in any of the following ways:

number
Specifies the character as a numerical index, where 0 corresponds to the first character in the string.

@number
In this form, number is treated as an x-coordinate in the entry's window; the character spanning that x-coordinate is used. For example, “@0” indicates the left-most character in the window.

end
Indicates the character just after the last one in the entry's string. This is equivalent to specifying a numerical index equal to the length of the entry's string.

insert
Indicates the character adjacent to and immediately following the insert cursor.

sel.first
Indicates the first character in the selection. It is an error to use this form if the selection is not in the entry window.

sel.last
Indicates the character just after the last one in the selection. It is an error to use this form if the selection is not in the entry window.

Abbreviations may be used for any of the forms above, e.g. “e” or “sel.l”. In general, out-of-range indices are automatically rounded to the nearest legal value.

Generally speaking, the insight of subcommands corresponding to methods applies relatively easily (and is directly used in the main object systems for Tcl) though it gets a little bit tricky with sub-subcommands. In effect, the method delegates to an inner object for dispatch.

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