Purpose: describe what the term widget means
A widget is a term used in graphical user interface (GUI) circles in connection to some component of a GUI application. While most widgets have the potential of visual representation, this need not be the case - for instance, container widgets like frames don't actually show up on the screen.
See Tk syntax help for a list of Tk specific commands, some of which are widgets:
Note that in Tk, one has several ways one can control visual aspects of widgets:
[are there other ways of influencing these?]
Some systems call these "controls." I've also heard "gadgets." -- CLN
EE: From The X Window System: Programming And Applications With Xt, OSF/Motif Edition by Douglas A. Young. (First edition, sixth printing, published in 1990):
In addition to widgets, Motif provides a user interface component known as a gadget. Gadgets are identical to widgets, except that they have no window of their own. A gadget must display text or graphics in the window provided by its parent, and must also rely on its parent for input. [...] From the application programmer's viewpoint, gadgets can be used exactly the same way as other display widgets, except for the following restrictions. Gadgets cannot support event handlers, translations, or popup children. Gadgets can support callback functions and have the same appearance as the corresponding widgets.
Widgets are a part of Tk as well as alternatives.
DKF 17Dec02 - For a more modern example of the difference, Java Swing is almost entirely gadget-based, whereas AWT is pretty-much completely widget-based (though they use different terminology: lightweight and heavyweight Components.)
One must be certain to keep some things in mind when writing widget code.
It's also not a good idea at all to start a widget name part with a capital letter (because that style of name is reserved for the names of widget classes, and you *really* don't want to get those two mixed up.) But it's usually really easy to start with a lower-case letter and use alphanumeric for the rest...
[Using :: as characters in a widgets name as a] problem is much more difficult to get around for megawidget authors than the space one. Properly treating things as lists solves the space problem. However, the use of namespaces for megawidget building is common in order to encapsulate code / hide the ickies from the user. That conflicts with the use of ::. It is possible to rename the :: parts when you use namespaces, but then it becomes cumbersome to map back and forth.
RS As each widget defines a command with its name, can't interp aliases be used to map fancy to real names? E.g.
interp alias {} foo::bar {} .top.frame1.bar.canvas
LV So, if someone has a string that they are certain is a name of a widget, is there introspection that can be used to determine what widget it is?
escargo 16 Aug 2005 - I would expect winfo exists should be able to answer that question.
LV winfo exists just tells me if the widget exists - not what kind of a widget it is. Thanks!
MG How about winfo class $widgetName?
LV That seems like it should work - thanks!
Notye (<== should this be 'Notice'? rdt) that there is actually a Tk extension known as widget as well. Written by JH, it is a Tk megawidget framework (found at MegaWidget package).
LV and now tklib has a widget module which is to contain a variety of megawidgets. The initial ones are snidgets, but the creator of the tklib widget module says that megawidgets in other OO packages... say XOTcl ... are also possible.
tklib's widget package contains the following megawidgets:
Right now, I'd just like to see people start contributing widgets to tklib ;-) ...
ABU 25-Jan-2006
I'd like to see documentation and demos - in general, many tklib modules are not well documented :-(
RS 2006-04-28: Here's a little helper to retrieve the default value of a widget attribute (use long names (-background) instead of the short ones (-bg)):
% proc get'default {w flag} {lindex [$w config $flag] 3} % get'default $t -font {MS Sans Serif} 8
The current value is of course returned by the cget method:
% $t cget -font Courier 9
[ Category GUI | Category Data Structure | Category Concept | Category Glossary | ]