Jérôme Quelin

NAME

Tk::Sugar - Sugar syntax for Tk

VERSION

version 1.093190

SYNOPSIS

    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'

DESCRIPTION

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.

EXPORTS

This module is using Sub::Exporter underneath, so you can use all its shenanigans to change the export names.

Exported subs

Look below for the list of available subs.

Pack options

Traditional packer sides (available as :side export group):

  • top - equivalent to ( -side => 'top' )

  • bottom - ditto for bottom

  • left - ditto for left

  • right - ditto for right

Packer expand and filling (available as :fill export group):

  • fillx - equivalent to ( -fill => 'x' )

  • filly - equivalent to ( -fill => 'y' )

  • fill2 - equivalent to ( -fill => 'both' )

  • xfillx - same as fillx with ( -expand => 1 )

  • xfilly - ditto for filly

  • xfill2 - ditto for fill2

  • expand - equivalent to ( -expand => 1 ) if you don't like the xfill* notation

Packer padding (available as :pad export group):

  • pad1 - equivalent to ( -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):

  • ipad1 - equivalent to ( -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)

Common options

Widget state (available as :state export group):

  • enabled - equivalent to ( -state => 'normal' )

  • disabled - ditto for 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:

  • N - equivalent to ( -anchor => 'n' )

  • S - ditto with s

  • E - ditto with e

  • W - ditto with w

  • C - ditto with center

  • NE - ditto with ne

  • NW - ditto with nw

  • SE - ditto with se

  • SW - ditto with sw

Widget orientation (available as :orient export group).:

  • horizontal - equivalent to ( -orient => 'horizontal' )

  • vertical - ditto with vertical

Export groups

Beside the individual groups outlined above, the following export groups exist for your convenience:

:default

This exports all existing subs.

:pack

This exports subs related to Tk::pack options. Same as :side, :fill, :pad and :ipad.

:options

This exports subs related to widget configure options. Same as :state, :anchor and :orient.

SEE ALSO

You can look for information on this module at:

AUTHOR

  Jerome Quelin

COPYRIGHT AND LICENSE

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.




Hosting generously
sponsored by Bytemark