Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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
Re^2: Perl/TK: how to set defaults for the whole script?
by perltux (Beadle) 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 chanting in the Monastery: (6)
As of 2014-07-30 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls