Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

tk::optionmenu(3) [centos man page]

Optionmenu(3)						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, " " }, -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; SEE ALSO
Tk::Menubutton, Tk::BrowseEntry perl v5.16.3 2014-06-10 Optionmenu(3)

Check Out this Related Man Page

HistEntry(3pm)						User Contributed Perl Documentation					    HistEntry(3pm)

NAME
Tk::HistEntry - Entry widget with history capability SYNOPSIS
use Tk::HistEntry; $hist1 = $top->HistEntry(-textvariable => $var1); $hist2 = $top->SimpleHistEntry(-textvariable => $var2); DESCRIPTION
"Tk::HistEntry" defines entry widgets with history capabilities. The widgets come in two flavours: "HistEntry" (in package "Tk::HistEntry::Browse") - with associated browse entry "SimpleHistEntry" (in package "Tk::HistEntry::Simple") - plain widget without browse entry The user may browse with the Up and Down keys through the history list. New history entries may be added either manually by binding the Return key to historyAdd() or automatically by setting the -command option. OPTIONS
HistEntry is an descendant of BrowseEntry and thus supports all of its standard options. SimpleHistEntry is an descendant of Entry and supports all of the Entry options. In addition, the widgets support following specific options: -textvariable or -variable Variable which is tied to the HistEntry widget. Either -textvariable (like in Entry) or -variable (like in BrowseEntry) may be used. -command Specifies a callback, which is executed when the Return key was pressed or the invoke method is called. The callback reveives three arguments: the reference to the HistEntry widget, the current textvariable value and a boolean value, which tells whether the string was added to the history list (e.g. duplicates and empty values are not added to the history list). -dup Specifies whether duplicate entries are allowed in the history list. Defaults to true. -bell If set to true, rings the bell if the user tries to move off of the history or if a search was not successful. Defaults to true. -limit Limits the number of history entries. Defaults to unlimited. -match Turns auto-completion on. -case If set to true a true value, then be case sensitive on auto-completion. Defaults to 1. METHODS
historyAdd([string]) Adds string (or the current textvariable value if not set) manually to the history list. addhistory is an alias for historyAdd. Returns the added string or undef if no addition was made. invoke([string]) Invokes the command specified with -command. history([arrayref]) Without argument, returns the current history list. With argument (a reference to an array), replaces the history list. historySave(file) Save the history list to the named file. historyMergeFromFile(file) Merge the history list from the named file to the end of the current history list of the widget. historyReset Remove all entries from the history list. KEY BINDINGS
Up, Control-p Selects the previous history entry. Down, Control-n Selects the next history entry. Meta-<, Alt-< Selects first entry. Meta->, Alt-> Selects last entry. Control-r The current content of the widget is searched backward in the history. Control-s The current content of the widget is searched forward in the history. Return If -command is set, adds current content to the history list and executes the associated callback. EXAMPLE
This is an simple example for Tk::HistEntry. More examples can be found in the t and examples directories of the source distribution. use Tk; use Tk::HistEntry; $top = new MainWindow; $he = $top->HistEntry(-textvariable => $foo, -command => sub { # automatically adds $foo to history print STDERR "Do something with $foo "; })->pack; $b = $top->Button(-text => 'Do it', -command => sub { $he->invoke })->pack; MainLoop; If you like to not depend on the installation of Tk::HistEntry, you can write something like this: $Entry = "Entry"; # default Entry widget eval { # try loading the module, otherwise $Entry is left to the value "Entry" require Tk::HistEntry; $Entry = "SimpleHistEntry"; }; $entry = $mw->$Entry(-textvariable => $res)->pack; $entry->bind("<Return>" => sub { # check whether the historyAdd method is # known to the widget if ($entry->can('historyAdd')) { $entry->historyAdd; } }); In this approach the history lives in an array variable. Here the entry widget does not need to be permanent, that is, it is possible to destroy the containing window and restore the history again: $Entry = "Entry"; eval { require Tk::HistEntry; $Entry = "HistEntry"; }; $entry = $mw->$Entry(-textvariable => $res)->pack; if ($entry->can('history') && @history) { $entry->history(@history); } # Later, after clicking on a hypothetical "Ok" button: if ($res ne "" && $entry->can('historyAdd')) { $entry->historyAdd($res); @history = $entry->history; } BUGS
/TODO - C-s/C-r do not work as nice as in gnu readline - use -browsecmd from Tk::BrowseEntry - use Tie::Array if present AUTHOR
Slaven Rezic <slaven@rezic.de> CREDITS
Thanks for Jason Smith <smithj4@rpi.edu> and Benny Khoo <kkhoo1@penang.intel.com> for their suggestions. The auto-completion code is stolen from Tk::IntEntry by Dave Collins <Dave.Collins@tiuk.ti.com>. COPYRIGHT
Copyright (c) 1997, 2000, 2001, 2003 Slaven Rezic. All rights reserved. This package is free software; you can redistribute it and/or mod- ify it under the same terms as Perl itself. perl v5.8.8 2007-02-02 HistEntry(3pm)
Man Page