O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Item Styles

Creating and using a style is very similar to creating and using a tag in the Text widget, except you get a bit more reusability with Tix item styles. If you predefine what you’d like the style to look like, you can use it throughout your program many times with different Tix widgets. If you need to change how those items are displayed, you can change the definition of the style instead of changing each individual item.

To create a new style, call the ItemStyle method:

$styleref = $parentwidget->ItemStyle('text', 
       -stylename => 'stylename', 
       [ option => value, ... ] );

The first parameter to ItemStyle must be an item type (image, text, imagetext, or window). What $parentwidget you use is important only because it determines the default values of all the style options. If you use a TList as the parent widget, with a default font of "Courier 14", then the style will use that font unless the -font option is explicitly changed. You can use any widget as the parent widget, including the MainWindow ($mw).

The rest of the arguments to ItemStyle are option/value pairs. You can use any of the following option/value pairs with ItemStyle:

-stylename => ' stylename '

Gives the style a name. Note that you don’t really need this, because you use the reference to the style when creating items, not the name of the style. However, it’s useful if you intend to let users create and manipulate styles, since it might help them remember which style is which.

-refwindow => $otherwidget

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required