Thanks Jeff for an informative answer. I also found <http://www.tkdocs.com/tutorial/styles.html > worth reading.

--Gisle

On Jan 27, 2009, at 1:52 , Jeff Hobbs wrote:

Gisle Aas wrote:
On Jan 23, 2009, at 18:03 , Jeff Hobbs wrote:
Yes, it is necessary due to the limitation on widgets that accept - class. Note that using -class has more effect than just changing the response to g_winfo_class. It modifies the class bindings and those applied by Xdefaults and the option database.
Jeff, I don't really understand this stuff well, so I hope you can give some more general advise. Is it a good idea to set the -class for the root frame of Perl based megawidgets? What are the frame class binding you miss out on when you set the - class to something else than "Frame" or "TFrame" yourself?

There are no Frame or TFrame bindings by default, so setting them is generally a good idea. However, all the new ttk::* widgets also take -class, adding a little more flexibility - if you haven't it right.

Recall that bindings in Tk are managed as a list of possible tags. This list is managed with bindtags and defaults to:

        [$instance, $class, $toplevelOfInstance, 'all']

http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/bindtags.htm

Widget instances are empty by default, Tk has all the default class bindings, the toplevel tag is used to group events (like Ctrl-w to close this window), and all is the catch-all (Ctrl-q for quit).

When dealing with megawidgets, it is recommended to declare a distinct class name for the megawidget. Sometimes when creating an extended widget that has no outer frame (common with the text or canvas), then I just insert a new class tag before the standard class tag so I can supercede standard class bindings (the binding chain can be broken by returning certain codes ... hmmm, I haven't thought about how that would translate for Tkx). The point is that it gives you a single point of grouping a set of behaviors for a megawidget.

Isn't the options database and the Xdefaults stuff just legacy? Does it apply under OS X, Windows or KDE? Is it actually used by the new themed widgets?

Actually, Xdefaults works across the platforms, in that Tk can read those files, and you can create interesting preferences files using the whole option schema (as discussed in the Welch book on Tcl/Tk). The new themed widgets mostly ignore the option database, but you can still build on that.

Jeff

Reply via email to