Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Perl/TK: how to set defaults for the whole script?

by kcott (Abbot)
on Oct 24, 2012 at 08:24 UTC ( #1000570=note: print w/ replies, xml ) Need Help??


in reply to Perl/TK: how to set defaults for the whole script?

G'day perltux,

You can put all your default options in a hash.

my %default_scale_options = ( -width => '10', -length => '200', -sliderlength => '16', -orient => 'horizontal', -borderwidth => '1', -cursor => 'hand2', -showvalue => '0' ); ... my $scale1 = $parent->Scale(%default_scale_options); ... my $scaleN = $parent->Scale(%default_scale_options);

An alternative to this is to use an option database. You can set this up external to your script (e.g. with a .Xdefaults file) allowing access by multiple scripts; you can also use optionAdd(), and related methods, to handle options within a single script. See option for details.

Here's an example of usage extracted from one of my own scripts. configure_option_database() is called after MainWindow->new() but before any widgets are created.

sub configure_option_database { ... my $priority = 'startupFile'; # 40 ... # Button $mw->optionAdd('*Button*borderWidth', 1, $priority); $mw->optionAdd('*Button*activeBorderWidth', 1, $priority); ... # Entry $mw->optionAdd('*Entry*background', '#ffffff', $priority); $mw->optionAdd('*Entry*borderWidth', 1, $priority); $mw->optionAdd('*Entry*cursor', 'xterm', $priority); ... }

-- Ken


Comment on Re: Perl/TK: how to set defaults for the whole script?
Select or Download Code
Replies are listed 'Best First'.
Re^2: Perl/TK: how to set defaults for the whole script?
by perltux (Scribe) on Oct 24, 2012 at 09:11 UTC
    Thanks, in this case I will use the hash solution, the options database solution looks interesting too, but is overkill in this case for my specific script.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000570]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2015-07-31 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls