Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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

by kcott (Canon)
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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000570]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-03-27 22:27 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (324 votes). Check out past polls.