Using the Option Database
The option database is populated by
several mechanisms. We already know
Tk::CmdLine::SetArguments
sets standard X11
options prior to MainWindow creation. Unix users should be familiar
with the .Xdefaults file, a simple text file
that can contain resource entries and is one of the files
Tk::CmdLine::SetArguments
reads during MainWindow
initialization. Perl/Tk programs can load resources from other files
as well by calling
Tk::CmdLine::LoadResources
or optionReadfile
.
Or, Tk::CmdLine::SetResources
and
optionAdd
can add individual resources to the
option database. For the location of other resources files, please
read the manpage for Tk::CmdLine
.
Here are some sample resource entries:
*font : 12x24 frog*Foreground : blue frog.button1.Background : orange frog.b3.foreground : green frog*Label*cursor : gobbler
Note that the resource pattern is to the left of the colon, and its
value to the right. The pattern can be general (such as the first
entry, which changes the default font for every X and Tk application)
or specific (such as the fourth entry, which changes only the
foreground color of the widget named b3
of the
application frog).
A resource pattern identifies an option and one or more widgets in the window hierarchy. Tk generates the hierarchy automatically, assigning string pathnames to each widget. In Chapter 13, we learned that Tcl/Tk programmers are required to do this manually. In Perl/Tk, we seldom need to refer to widget pathnames; ...
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.