#!/usr/bin/perl use strict; use warnings; use Tk; my @choices = qw/Apple Ball Cat Dog Elephant Fish Goat House Ink Jug Kite/; my $choice = &myListBox(@choices); print "Selection is $choice\n"; sub myListBox{ my $choice; my @listbox_items = @_; my $mw = MainWindow->new; $mw->title("Listbox"); my $lb = $mw->Scrolled("Listbox", -scrollbars => "osoe", -height => 10, -width => 30, -selectmode => "single"); my $real_lb = $lb->Subwidget('scrolled'); $real_lb->configure(-borderwidth=>0); $lb->insert("end", @listbox_items); $lb->pack(-side => "left"); $mw->Button(-text => "Exit", -command => sub{exit; })->pack(-side => "bottom"); $mw->Button(-text=>"View", -command => sub { $choice= $lb->get('active'); my $w = $real_lb->width; my $sample = ' ' x 10; my $font_len = $lb->fontMeasure('default', $sample ); } )->pack(-side => "bottom"); $lb->selectionSet('end'); $lb->see('end'); MainLoop; return $choice; }