Go to main content

man pages section 3: Library Interfaces and Headers

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

Tk::Optionmenu (3)

Name

Tk::Optionmenu - Let the user select one of some predefined options values

Synopsis

use Tk::Optionmenu;

$opt = $w->Optionmenu(
-options => REFERENCE_to_OPTIONLIST,
-command => CALLBACK,
-variable => SCALAR_REF,
);

$opt->addOptions( OPTIONLIST );

# OPTION LIST is
#   a)  $val1, $val2, $val3,...
#   b)  [ $lab1=>$val1], [$lab2=>val2], ... ]
#   c)  combination of a) and b), e.g.,
#       val1, [$lab2=>val2], val3, val4, [...], ...

Description

User Contributed Perl Documentation                              Optionmenu(3)



NAME
       Tk::Optionmenu - Let the user select one of some predefined options
       values

SYNOPSIS
           use Tk::Optionmenu;

           $opt = $w->Optionmenu(
                               -options => REFERENCE_to_OPTIONLIST,
                               -command => CALLBACK,
                               -variable => SCALAR_REF,
                               );

           $opt->addOptions( OPTIONLIST );

           # OPTION LIST is
           #   a)  $val1, $val2, $val3,...
           #   b)  [ $lab1=>$val1], [$lab2=>val2], ... ]
           #   c)  combination of a) and b), e.g.,
           #       val1, [$lab2=>val2], val3, val4, [...], ...

DESCRIPTION
       The Optionmenu widget allows the user chose between a given set of
       options.

       If the user should be able to change the available option have a look
       at Tk::BrowseEntry.

OPTIONS
       -options
           (Re)sets the list of options presented.

       -command
           Defines the callback that is invokes when a new option is selected.

       -variable
           Reference to a scalar that contains the current value of the
           selected option.

       -textvariable
           Reference to a scalar that contains the text label of the current
           value of the selected option.

METHODS
       addOptions
           Adds OPTION_LIST to the already available options.

EXAMPLE
        use Tk;
        my $mw = MainWindow->new();

        my ($var, $tvar);
        my $opt = $mw->Optionmenu(
               -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]],
               -command => sub { print "got: ", shift, "\n" },
               -variable => \$var,
               -textvariable => \$tvar
              )->pack;

        $opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]);

        my $f = $mw->Frame(-relief=>'groove', -borderwidth => 2)->pack;
        $f->Label(-textvariable=>\$tvar)->pack(-side => 'left');
        $f->Label(-text => " -> ")->pack(-side => 'left');
        $f->Label(-textvariable=>\$var)->pack(-side => 'left');

        $mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack;

        MainLoop;


ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:


       +---------------+----------------------------+
       |ATTRIBUTE TYPE |      ATTRIBUTE VALUE       |
       +---------------+----------------------------+
       |Availability   | library/perl-5/perl-tk-532 |
       +---------------+----------------------------+
       |Stability      | Volatile                   |
       +---------------+----------------------------+

SEE ALSO
       Tk::Menubutton, Tk::BrowseEntry



NOTES
       Source code for open source software components in Oracle Solaris can
       be found at https://www.oracle.com/downloads/opensource/solaris-source-
       code-downloads.html.

       This software was built from source available at
       https://github.com/oracle/solaris-userland.  The original community
       source was downloaded from
       http://search.cpan.org/CPAN/authors/id/S/SR/SREZIC/Tk-804.036.tar.gz.

       Further information about this software can be found on the open source
       community website at http://search.cpan.org/~srezic/Tk.



perl v5.32.0                      2013-11-15                     Optionmenu(3)