The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tk::CompoundButton - Enhanced Button widget with a bitmap/image AND a text label

SYNOPSIS

    use Tk;
    use Tk::CompoundButton

    my $mw = MainWindow->new();

    my $downangle_data = <<'downangle_EOP';
    /* XPM */
    static char *arrow[] = {
    "14 9 2 1",
    ". c none",
    "X c black",
    "..............",
    "..............",
    ".XXXXXXXXXXXX.",
    "..XXXXXXXXXX..",
    "...XXXXXXXX...",
    "....XXXXXX....",
    ".....XXXX.....",
    "......XX......",
    "..............",
    };
    downangle_EOP

    my $downangle = $mw->Pixmap( -data => $downangle_data);

    my $text = 'bttn-text';
    my $bt1 = $mw->CompoundButton(
                #-padx => -1,
                -text => 'Enable',
                -image => $downangle,
        -bitmap => 'error',
                -command => \&bttn_pressed_cb1,
                #-borderwidth => '12',
                #-relief => 'ridge',
                -bg => 'orange',
                -fg => 'green',
                -textvariable => \$var,
                -side => 'bottom',
#               -side => 'top',
#               -side => 'left',
                -activebackground => 'red',
                -activeforeground => 'blue',
#               -width => 200,
                -height => 200,
                #-anchor => 'sw',
                #-anchor => 'e',
                #-justify => 'right',
                -gap => 20,
   )->pack(-padx => 50, -pady => 50);

    my $bt2 = $mw->Button(
            -text => 'Disable',
            -command => [\&bttn_pressed_cb2, $bt1],
            #-image => $downangle,
    )->pack;

        
    Tk::MainLoop;
        
    sub bttn_pressed_cb1
    {
        print "bttn 1 pressed.\n";

    }
    sub bttn_pressed_cb2
    {
        print "bttn 2 pressed.\n";
        $_[0]->configure(-state => ($_[0]->cget('-state') eq 'normal' ? 'disabled' : 'normal'));
    }
        

DESCRIPTION

A Button widget that can be used as a replacement for the standard Button, if you want to display a bitmap/image AND a text label.

METHODS

for details on supported methods - see also Tk::Button

OPTIONS

-side

-side => 'value' allows to specify the side at which the bitmap/image is positioned. Value may be one of top, left, bottom or right.

-gap

-gap => 'value' allows to specify the size of the gap between the bitmap/image and the text. default is 5px.

-textjustify

-textjustify => 'value' allows to justify the text independant from the image item. Usable values are [left, right, center, or none], default is none. Normally image and text are placed as a contiguous block on either side according -anchor option. Using this option allows to break this rule. Example: -textjustify allows for a column of buttons of same size to have all images on the right corner and the text in front of it centered in respect ot the overall button-width:

 Default Mode: 
 +----------------+  +----------------+  +----------------+
 |        Text IMG|  |Text IMG        |  |   Text IMG     |
 +----------------+  +----------------+  +----------------+
 -anchor => 'e',       -anchor => 'w'      -anchor => 'e'
 -side   => 'right'    -side   => 'right'  -side   => 'right'



 textjustify Mode:
 +----------------+  +----------------+  +----------------+
 |Text         IMG|  |     Text    IMG|  |        Text IMG|
 +----------------+  +----------------+  +----------------+
 -anchor => 'e'      -anchor => 'e'      -anchor => 'e'
 -textjustify        -textjustify        -textjustify
       => 'left'           => 'center'         => 'center'
 -side => 'right'    -side => 'right'    -side => 'right'

NOTE: -textjustify does work only, if you specify also a fixed WIDTH of the button. Furthermore it does not work with -bitmap option, only -image.

***

For details on all other options especially -anchor, and -justify see Tk::Button.

This widget is fully backward compatible to the standard Tk::Button and thus supports all options found there.

AUTHORS

Michael Krause, KrauseM_AT_gmx_DOT_net

This code may be distributed under the same conditions as Perl.

V0.3 (C) 2004 - 2009