I've managed to write a working widget with a Listbox. But I cannot find a way to Scroll the Listbox within the widget. (Search for 'Scrolled') See these two pieces of code and lines.

Scenario

perl testPicker.pl

HELP!!!

testPicker.pl

#!/usr/bin/perl -w use Tk; use Picker; use strict; my $mw= MainWindow->new; my $ep= $mw->Picker(-title=> 'Entity Picker'); # should return an entity key my $choice= $ep->Show; print "$choice\n"; $mw->destroy; MainLoop;

Picker.pm is

$Tk::Picker::VERSION= '1.0'; package Tk::Picker; use Tk::Listbox; use base qw/Tk::Derived Tk::DialogBox/; use subs qw/build/; use strict; Construct Tk::Widget 'Picker'; # Class global variables sub build($); # Class initializer. sub ClassInit($$) { my ($class, $mw)= @_; $class->SUPER::ClassInit($mw); return 1; } our @fields= ( qw/ AUSTIN AUTUN AVA AVERY AYDEN BAILEY BENJAMIN BENNY BIANCA BILLIE BILLY BLAKE BRADEN BRADLEY BRADY BRANDON BRAYDEN BREANNA BRENDAN BRIAN BRIANA BRIANNA BRITTANY BRODY BROOKE BROOKLYN BRYAN BRYCE BRYSON CADEN CAITLIN CAITLYN CALEB CAMERON CAILA CARLOS CAROL CAROLINE CARSON CARTER CASSANDRA CASSIDY CATHERINE CESAR CHARLES CHARLOTTE CHASE CHELSEA CHEYENNE CHLOE CHRISTIAN CHRISTINA CHRISTOPHER CLAIRE CODY COLBY COLE COLIN COLLIN COLTON CONNER CONNOR COOPER COURTNEY CRISTIAN CRYSTAL DAISY DAKOTA DALTON DAMIAN DANIEL DANIELA DANIELLE DAVID DELANEY DEREK DESTINY DEVIN DEVON / ); sub Populate($$) { my ($self, $args)= @_; $args->{'-buttons'} = ['Cancel', 'Select' ] unless defined $args->{'-buttons'}; $self->SUPER::Populate($args); $self->build; } # subroutines sub build($); sub buttonPress($$) { my ($self, $param)= @_; print "$param\n"; push @fields, "Name" . $#fields; $self->build; } sub build($) { my ($self)= @_; $self->title("My Picker"); $self->Component('Label', 'label1', -text=>"Select a name", -background=>"lightblue")->pack; # how to make a scrolled Listbox??? # does not compile... # So - shouldn't Component accept a nested Component somehow?? # my $sbox= $self->Component('Scrolled', 'scroll', # $self->Component('Listbox', 'sbox', # -selectmode=>'single', # -font=>'ansifixed', # -width=>20, # -height=>15, # ), # -scrollbars=>'osoe' # )->pack; # an unscrolled Listbox my $lbox= $self->Component('Listbox', 'lbox', -selectmode=>'single', -font=>'ansifixed', -width=>20, -height=>15, )->pack; $lbox->insert('end', @fields); $self->{lbox}= $lbox; } sub Show($) { my ($self)= @_; $self->Popup; $self->waitVariable(\$self->{'selected_button'}); return 'Cancel' if ($self->{'selected_button'} eq 'Cancel'); my $cvalue= $self->{lbox}->curselection; return 'No selection' if ($#$cvalue < 0); return $fields[$cvalue->[0]]; } 1;

In reply to Widget with Scrolled Listbox by wbarrett

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.