Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Creating GUI's that work across several versions of Tk

by strat (Canon)
on May 29, 2006 at 07:56 UTC ( #552262=note: print w/replies, xml ) Need Help??

in reply to Creating GUI's that work across several versions of Tk

I always try to keep the Tk code within one or two modules e.g. MyApp::Widgets which contains little wrapper subroutines for the widgets I use, e.g

package MyApp::Widgets; ... sub Button { my ($parent, $text, $callback, %options) = @_; if (ref $text) { $options{-textvariable} = $text } else { $options{-text} = $text } if (ref($callback) ....) { $options{-command} = $callback; } else { $options{-background} = '#ff0000'; } # else return $parent->Button( -font => $StdButtonFont, -background => '#ffdd00', %options, ); } # Button

or the like (code not tested)

and perhaps MyApp::Callbacks) which contains the whole callbacks to Tk. It's not too beautiful to call such a sub (e.g. my $button = &MyApp::Widgets::Button($parent, 'bla', sub { print "Exit }, -font => $BoldFont);), but this way I can give every widget default properties very easily; in addition to that, the whole Tk-Code is bundled within one or two modules which can easily be exchanged based on the Tk version by an installer or the like)

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2016-10-28 12:15 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.