Tk::CompoundButton - Enhanced Button widget with a bitmap/image B<AND> a text label |
Tk::CompoundButton - Enhanced Button widget with a bitmap/image AND a text label
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')); }
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.
for details on supported methods - see also Tk::Button
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.
Michael Krause, KrauseM_AT_gmx_DOT_net
This code may be distributed under the same conditions as Perl.
V0.3 (C) 2004 - 2009
Tk::CompoundButton - Enhanced Button widget with a bitmap/image B<AND> a text label |