Tk::Sugar - Sugar syntax for Tk
version 1.093190
use Tk::Sugar qw{ :pack :state }; $widget->pack( top, xfill2, pad10 ); # equivalent to those pack options: # -side => 'top' # -expand => 1 # -fill => 'both' # -padx => 10 # -pady => 10 $widget->configure( enabled ); # equivalent to: -state => 'enabled'
Tk is a great graphical toolkit to write desktop applications. However, one can get bothered with the constant typing of quotes and options. Tk::Sugar provides handy subs for common options used when programming Tk.
Benefits are obvious:
Reduced typing.
The constant need to type => and '' is fine for one-off cases, but the instant you start using Tk it starts to get annoying.
=>
''
More compact statements.
Reduces much of the redundant typing in most cases, which makes your life easier, and makes it take up less visual space, which makes it faster to read.
No string worries.
Strings are often problematic, since they aren't checked at compile- time. Sometimes it makes spotting an error a difficult task. Using this alleviates that worry.
This module is using Sub::Exporter underneath, so you can use all its shenanigans to change the export names.
Look below for the list of available subs.
Traditional packer sides (available as :side export group):
:side
top - equivalent to ( -side => 'top' )
( -side => 'top' )
bottom - ditto for bottom
bottom
left - ditto for left
left
right - ditto for right
right
Packer expand and filling (available as :fill export group):
:fill
fillx - equivalent to ( -fill => 'x' )
( -fill => 'x' )
filly - equivalent to ( -fill => 'y' )
( -fill => 'y' )
fill2 - equivalent to ( -fill => 'both' )
( -fill => 'both' )
xfillx - same as fillx with ( -expand => 1 )
fillx
( -expand => 1 )
xfilly - ditto for filly
filly
xfill2 - ditto for fill2
fill2
expand - equivalent to ( -expand => 1 ) if you don't like the xfill* notation
xfill*
Packer padding (available as :pad export group):
:pad
pad1 - equivalent to ( -padx => 1, -pady => 1 )
( -padx => 1, -pady => 1 )
pad2 - ditto with 2 pixels
pad5 - ditto with 5 pixels
pad10 - ditto with 10 pixels
pad20 - ditto with 20 pixels
pad($n) - ditto with $n pixels (function call with one argument)
padx($n) - x padding with $n pixels (function call with one argument)
pady($n) - y padding with $n pixels (function call with one argument)
Packer padding (available as :ipad export group):
:ipad
ipad1 - equivalent to ( -ipadx => 1, -ipady => 1 )
( -ipadx => 1, -ipady => 1 )
ipad2 - ditto with 2 pixels
ipad5 - ditto with 5 pixels
ipad10 - ditto with 10 pixels
ipad20 - ditto with 20 pixels
ipad($n) - ditto with $n pixels (function call with one argument)
ipadx($n) - internal x padding with $n pixels (function call with one argument)
ipady($n) - internal y padding with $n pixels (function call with one argument)
Widget state (available as :state export group):
:state
enabled - equivalent to ( -state => 'normal' )
( -state => 'normal' )
disabled - ditto for disabled
disabled
Widget anchor (available as :anchor export group). Note that those subs are upper case, otherwise the sub s would clash with the regex substitution:
:anchor
s
N - equivalent to ( -anchor => 'n' )
( -anchor => 'n' )
S - ditto with s
E - ditto with e
e
W - ditto with w
w
C - ditto with center
center
NE - ditto with ne
ne
NW - ditto with nw
nw
SE - ditto with se
se
SW - ditto with sw
sw
Widget orientation (available as :orient export group).:
:orient
horizontal - equivalent to ( -orient => 'horizontal' )
( -orient => 'horizontal' )
vertical - ditto with vertical
vertical
Beside the individual groups outlined above, the following export groups exist for your convenience:
This exports all existing subs.
This exports subs related to Tk::pack options. Same as :side, :fill, :pad and :ipad.
This exports subs related to widget configure options. Same as :state, :anchor and :orient.
You can look for information on this module at:
Search CPAN
http://search.cpan.org/dist/Tk-Sugar/
Open / report bugs
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-Sugar
Git repository
http://github.com/jquelin/tk-sugar.git
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Tk-Sugar
CPAN Ratings
http://cpanratings.perl.org/d/Tk-Sugar
Jerome Quelin
This software is copyright (c) 2009 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Tk::Sugar, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tk::Sugar
CPAN shell
perl -MCPAN -e shell install Tk::Sugar
For more information on module installation, please visit the detailed CPAN module installation guide.