Tie::Tk::Listbox - Access Tk::Listbox and similar widgets as arrays
Current version is 1.01.
use Tk; use Tie::Tk::Listbox; $main = MainWindow->new; # Examples of scrollable and normal listboxes... $scroll = $main->Scrolled(qw/Listbox -height 25 -width 40 -selectmode extended -scrollbars oseo/)->pack(-side => 'left'); $listb = $main->Listbox(qw/-height 25 -width 40 -selectmode extended/)->pack(-side => 'right'); # Tie Scrolled or Listbox widgets the same way... tie @scr_ary => 'Tie::Tk::Listbox', $scroll; tie @list_ary => 'Tie::Tk::Listbox', $listb; # Initialize with data. @scr_ary = map {"$_: " . ('x' x $_)} 1..100; @list_ary = 'a'..'z'; # Do something with the arrays here or in callbacks... # Run MainLoop;
The Tie::Tk::Listbox module allows you to tie the contents of a Tk::Listbox widget to an ordinary Perl array for easy modification. Additionally, you may tie a Tk::Scrolled widget or any other widget that advertises a Tk::Listbox subwidget. Please see CAVEATS about this.
Except the DELETE and EXISTS methods, whose purpose is somewhat opaque to the author because they should not be used on arrays, all tied methods have been implemented to behave exactly as the functions that operate on ordinary Perl arrays. If you happen to find out that this is not the case, please report your discovery to the author.
When tying an array to widgets other than Tk::Listbox widgets, the tying routines will extract the reference to the Tk::Listbox widget using the Subwidget method on the enclosing widget. If that's Greek to you, don't worry: Either read "Subwidget" in Tk::mega on how to use advertised widgets. Or ignore this and don't use the tied function on the tied array because you will get the Tk::Listbox widget back, not the enclosing widget as you might expect.
Steffen Mueller, <tklistbox-module at steffen-mueller dot net<gt>
Copyright (c) 2003-2006 Steffen Mueller. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Test::More about the test suite
Tk and Tk::Listbox, as well as Tk::Scrolled
To install Tie::Tk::Listbox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Tk::Listbox
CPAN shell
perl -MCPAN -e shell install Tie::Tk::Listbox
For more information on module installation, please visit the detailed CPAN module installation guide.