Tk::EntrySet - display/edit a list of values in a Set of Widgets.
require Tk::EntrySet; my $valuelist = []; my $instance = $main_window->EntrySet()->pack; $instance->configure(-valuelist_variable => \$valuelist); $instance->valuelist([qw/foo bar baz/]);
Tk::EntrySet creates a Set of widgets to display/edit a list of values. The widget class is configurable. Tk::EntrySet adds/removes widgets to match the size of the valuelist. If a user deletes an entrywidgets content, the value is deleted from the valuelist and the entry is removed from the set on view update. View updates are by default bound to <Return> events. This is configurable through the -callback_installer option. The last widget in the Set is always empty to allow users to append values to the list. Tk::EntrySet is a Tk::Frame derived widget.
Tk::EntrySet supports the following methods:
Get/Set the valuelist (arrayref)
Tk::EntrySet supports the following options:
A Tk widget class to be used for the entrywidgets. Defaults to 'Entry'.
Options to be passed to each entry on creation (arrayref).
A coderef which is used by Tk::EntrySet to read the Entrywidgets content. It gets passed the Entrywidget instance and is expected to return its content. Defaults to sub{ $_[0]->get }, which is suitable for Tk::Entry.
A coderef which is used by Tk::EntrySet to write the Entrywidgets content. It gets passed the Entrywidget instance and the new value. Defaults to sub{ $_[0]->delete(0,'end'); $_[0]->insert('end',$_[1]) }, which is suitable for Tk::Entry.
A coderef which is called after each Entrywidgets instantiation. The callback_installer gets passed the Entrywidget and a coderef that will update the Tk::EntrySet view when called. Defaults to sub{$_[0]->bind('<Key-Return>',$_[1])}.
If set to true (default) empty strings will be treated like undef. Undef elements will be removed from the list and from the EntrySet on view updates.
If set to true (default) duplicate elements will be removed on view updates.
Get/Set the list of values (arrayref).
Ties a variable (scalarref) to the -valuelist atribute. This is a Scalar Tie only.
A Callback that is called after the valuelist is updated on user interaction. By default -changed_command is triggered if the user hits <Return> in any of the Entries. (See -callback_installer above if you want to change that.)
use strict; use warnings; use Tk; my $mw = MainWindow->new ; require Tk::EntrySet; my $valuelist = []; my $entryset = $mw->EntrySet()->pack; $entryset->configure(-valuelist_variable => \$valuelist); $entryset->valuelist([qw/foo bar baz/]); # use another entryclass: my $num_set = $mw->EntrySet(-entryclass => 'NumEntry')->pack; $num_set->valuelist([3,15,42]); # use a BrowseEntry with custom get/set/callback_installer: my $getter = sub{ $_[0]->Subwidget('entry')->get}; my $setter = sub{my $e = $_[0]->Subwidget('entry'); $e->delete(0,'end'); $e->insert('end', $_[1]); }; my $inst = sub{$_[0]->bind('<Key-Return>' ,$_[1]); $_[0]->configure(-browsecmd => $_[1]); }; my $mbe = $mw->EntrySet(-entryclass => 'BrowseEntry', -entryoptions => [-choices => [qw/ a b c d /]], -getter => $getter, -setter => $setter, -callback_installer => $inst, )->pack(-fill => 'both', -expand => 1); $mbe->valuelist([qw/a c/]); MainLoop;
Christoph Lamprecht, ch.l.ngre@online.de
Copyright (C) 2008 by Christoph Lamprecht
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
To install Tk::EntrySet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tk::EntrySet
CPAN shell
perl -MCPAN -e shell install Tk::EntrySet
For more information on module installation, please visit the detailed CPAN module installation guide.