Tk::PopUpSelectBox - A new scrolled pop-up selection-widget |
Tk::PopUpSelectBox - A new scrolled pop-up selection-widget (with MULTI-level selections)
use Tk; use Tk::PopUpSelectBox
my $current_class; my @all_classes = qw(cat dog bird); my $demo_xpm; my $mw = MainWindow->new(); # prepare some graphics setup_pixmap();
# create a demo my $popupselectbox = $mw->PopUpSelectBox ( -text => "Class", -image => $demo_xpm, # use this line for personal pics or #-bitmap => '@' . Tk->findINC('cbxarrow.xbm')); -command => \&class_cb, -options => [ @all_classes ], -variable => \$current_class, -tearoff => '1', -listmaxheight => 10, -activate => '0', )->pack; Tk::MainLoop; sub class_cb { print "class_cb called with [@_], \$current_class = >$current_class<\n"; } sub setup_pixmap { my $cbxarrow_data = <<'cbxarrow_EOP'; /* XPM */ static char *cbxarrow[] = { "11 14 2 1", ". c none", " c black", "...........", ".... ....", ".... ....", ".... ....", ".... ....", ".... ....", ". .", ".. ..", "... ...", ".... ....", "..... .....", "...........", ". .", ". ." }; cbxarrow_EOP
$demo_xpm = $mw->Pixmap(-data => $cbxarrow_data); }
A new dialog style widget that can replace the custom Optionbox whenever the itemlist is too long. Useful in applications that want to use a more flexible option menu. It's a 1:1 replacement for the custom Optionbox, supporting the same Options / commands.
You can tie a scalar-value to the Optionbox widget, enable/disable it, assign a callback, that is invoked each time the Optionbox is changed, as well as set Option-values and configure any of the options understood by Tk::Frame(s) like -relief, -bg, ... . (see docs of TK::Optionmenu) for details
NOTE: You should prefer interacting with the widget via a variable.
You should prefer to use a Configure ('-options' => ...).
NOTE: Unless You specify -activate => 0 for the widget each time you use add_options the first item will be set to be the current one and any assigned callback gets called.
plain format: label, label, [ label, value ], [ label, value ], [ label, value ], ... multi-level selection: The methodology is the same as before: Whenever instead of a label an Array-reference is found it is suggested as a subitem-list. It is poosible to mix plain items, items with spec'd values other than the label in any level. example: label, label, [ label, value ], [[keylabel, \@subopts], undef], [ label, value ], See the supplied example for further information.
Please see the TK:Optionmenu docs for details on all other aspects of these widgets.
Michael Krause, KrauseM_AT_gmx_DOT_net
This code may be distributed under the same conditions as Perl.
V0.02 (C) March 2008
Tk::PopUpSelectBox - A new scrolled pop-up selection-widget |