Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

by kcott (Chancellor)
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 (Monk) 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 meditating upon the Monastery: (7)
As of 2018-06-21 03:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.