Options for the Tk option database

May 3, 2001, 07:41 PM —  Unix Insider — 

In the first installment of this series, we mentioned three books as references for the use of the option database in its specific bindings to the Perl, Python, and Tcl languages (see the Resources section at the end of this article for pointers to this and other information). It was an oversight not to recommend Mark Harrison and Michael McLennan's Effective Tcl/Tk Programming at the same time. As master programmer and Expect inventor Don Libes wrote, "Their book is a gem and is the one that finally taught me to use the option database. They use options throughout the entire book -- which makes sense, since their whole book is about 'effective programming.'" Start with section 8.1, "Adding Polish to Your Application."

Effective Tcl makes good reading

Effective Tcl/Tk Programming is good reading for any Tk user, including those who rely on PerlTk and Tkinter. Last month we recommended John Grayson's book on Tkinter to anyone scripting graphical user interfaces, whatever the toolkit. Although Grayson's examples are exclusively in Python, his design principles transcend any particular language. Similarly, Harrison and McLennan communicate coding ideas that you'll find useful no matter what language you're using. For example, their presentation of Tk correctly emphasizes the power and flexibility of the built-in canvas and text widgets.

Effective Tcl/Tk Programming also gives a clear exposition on the use of a script as a configuration file to be evaluated. Sections 4.7.8, "Saving a Drawing," and 7.6.6.3, "Using Tcl Commands to Express Data," explore the notion that "Tcl commands are a powerful way of expressing data." Our last column gave several other examples showing that this holds true for commands in any scripting language.

Another strength of Harrison and McLennan's book is its presentation in chapter 7 of the event-based programming style that we've covered in past Regular Expressions columns.

Back to (optional) work

Recall from the first two installments of this series that Tk uses the option command for all actions taken against the option database. We've already looked at the option add and option readfile subcommands. In this column, we'll explain option clear and option get.

option clear resets all assignments made to the option database by previous option add or option readfile commands. The idea is to return to a fresh wish process, one initialized only with the platform-specific resource database values. Tk implements this by dropping all values, and, at the time of the next use of the resource database, re-reading the external ~/.Xdefaults. This can surprise newcomers. An example helps: if .Xdefaults in your home directory contains the line:


     *Button.background: cyan

and you run the script:


    
I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Free books

Build your tech library with our book giveaways.

Windows PowerShell 2.0 Unleashed
By Tyson Kopczynski, Pete Handley, Marco Shaw; Published by Sams

Windows PowerShell Unleashed will not only give you deep mastery over PowerShell but also a greater understanding of the features being introduced in PowerShell 2.0–and show you how to use it to solve your challenges in your production environment. Enter now!

 

Ubuntu Server Administration
By Michael Jang; Published by McGraw-Hill Osborne Media

Realize a dynamic, stable, and secure Ubuntu Server environment with expert guidance, tips, and techniques from a Linux professional. Ubuntu Server Administration covers every facet of system management -- from users and file systems to performance tuning and troubleshooting. Enter now!

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources