http://www.perlmonks.org?node_id=552262


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.8.8.32.11.32"