topics that matter; ideas worth sharing

share a tip, submit a link, add something new

Individualize your apps

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

Are you ready for more pizzazz in your GUI applications? Most GUI toolkits provide several ways to configure such widget characteristics as color, font, and size. For the first installment of this three-column series, we look specifically at the Tk toolkit and its option database.

Tk is quite portable, so the examples here work under Mac OS, Unix, and Windows, among other operating systems. What's more, although these examples are coded in Tcl/Tk, each one can be adapted immediately for the related PerlTk, Tkinter (Python), TkLua, and other Tk-derived bindings.

Many successful Tk programmers are barely aware of the option database. Recent books by John Grayson, Nancy Walsh, and Chris Nelson have only a couple of pages each on this subject, although all three of these books capture the essentials accurately. This continues a tradition begun by Tk's author, John Ousterhout, who wrote in his 1994 book:

The option database shouldn't be needed very often in Tk applications because widgets have reasonable default values.... The option database exists primarily to provide cultural compatibility with other X toolkits; I suggest that you use it as little as possible.

Tk does indeed "have reasonable default values"; even beginners can build quite useful GUIs with Tk. After this column, though, you'll have a better grasp of how to advance beyond that level.

Not a database to fear

Don't be afraid of the option database. It's really just a small, flat configuration file. In other words, you can examine and update it as a simple text file, without the structural and transactional overhead of more formal databases. Here's a minimal example of an option database: a file in your Unix $HOME directory called .Xdefaults with contents:


     *background: blue

In English, this says, "Make the default background color for all my widgets in all my X applications, including Tk applications, blue." The format and interpretation of option databases are portable to Mac OS, OpenVMS, and Windows; the next installment will provide a few platform-specific tips to help start you off right if you're not using Unix.

More generally, an option database is a file that lists key-value pairs. With it, you can customize the appearance of an application without making any changes to the code for that application. A common example is a specification that cranks up the font size for widgets. Suppose you create a Tk-based application and deliver copies to hundreds of users. Everything's going great, until a couple of users complain that the text is too tiny. The option database answers their need with no requirement to alter your application, pass it through

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.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff
Featured Sponsor

Get a broad understanding of important regulations and how you can make sure your site is in adherence.





Learn how VeriSign SGC-enabled SSL Certificates can help improve site security and customer confidence in the free white paper, "How to Offer the Strongest SSL Encryption." In this paper you will learn the differences between weak and strong encryption and what they mean for your site's performance.

Get VeriSign's free white paper: "The Latest Advancements in SSL Technology" and learn about the benefits of strong SSL encryption, Extended Validation (EV) SSL and security trust marks and what these SSL offerings can do for your site.

Now with Extended Validation (EV) SSL available from VeriSign, you can show your customers that they can trust your site. Learn about EV SSL benefits in this free VeriSign white paper.

More Resources