16.3. Option Databases

Under the X Window System, a file named .Xdefaults in the user's home directory contains configuration information for X applications, including the colors and fonts an application should use. You can create the same type of file for Win32 systems and call it whatever you want. You might use a file like this to let your users change the application's color settings.

Typically the lines in this file look something like this:

screen*background: yellow
screen.button.foreground:			green
screen*font: {Arial} 24 {normal}

The first item in each line should be the name of your application unless the options are for your application only. My test application was in a file named screen, so that is what I used as the first keyword in each line. The second keyword (if specified) is a widget type or name (you can specify a name for any widget by adding the -name option to the creation command of that widget). The third keyword is the "class" for which you want to set a default. You can set a default value for any of the options associated with a widget. See Appendix A to find out which class is associated with each widget type.

To read in this file, call optionReadfile with the location of the file (for example, "color_options" or "C:/.Xdefaults" or ".Xdefaults"):

$widget->optionReadfile("filename");

Make sure to include a newline on the last line of this file or you'll get an error that says, "missing newline on line 2 at C:\PERL\lib\site/Tk/Submethods.pm line 16." This ...

Get Learning 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.