Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use strict; # use warnings; use Tk; { # start package package Tk::ListBox3; use List::Util qw( first ); use base qw/ Tk::Frame /; # Frame-based composite Construct Tk::Widget 'ListBox3'; # install MyNewWidget in pTk namespac +e sub Populate # called to build each widget instance { my($self, $args) = @_; $self->SUPER::Populate($args); my $frame = $self->Frame( -borderwidth => 5, -relief => 'ridge', )->pack(-fill=> 'both', -expand=> 1); my $label = $frame->Label( -fg => 'blue', -font => 30, )->pack(-fill => 'x'); my $lbox = $frame->Scrolled(Listbox => -scrollbars => 'se', -height => 20, -selectforeground => 'orange', -selectbackground => 'steelblue4', -exportselection => 0, )->pack(-side => 'bottom', -fill => 'both', -expand=> 1); $frame->Entry( -validate => 'key', -validatecommand => sub { my ($want) = @_; length $want or return 1; my @list = $lbox->get(0 , "end"); my $item = first { $list[$_] =~ /^\Q$want\E/ } 0 .. $#list; defined $item or return 0; $lbox->selectionClear( 0 , "end" ); $lbox->selectionSet($item); $lbox->see($item); 1 # to allow }, )->pack(-fill => 'x'); $self->ConfigSpecs( DEFAULT => [$lbox], text => [$label],); $self->Delegates( Construct => $lbox, insert => $lbox, get => $lbox +); } } # end package my @choices = sort qw /alpha beta charlie delta echo foxtrot hotel ind +ia juliet kilo lima motel nancy oscar papa quebec radio sierra tango uniform v +ictor whiskey xray yankee zulu oin gloin beorn gandalf elr ond eowyn/; my $header_msg = "ENTER a KEY name: "; my $selection; my $mw = MainWindow->new; $mw->geometry( '+900+250' ); $mw->title( 'Listbox' ); my $lb = $mw->ListBox3( -text => $header_msg, )->pack(-fill => 'both', -expand => 1,); $lb->insert( 'end', @choices ); $mw->Button(-text => 'QUIT', -bg => 'red', -command => sub { $selection = $lb->get('active'); $mw->destroy }, )->pack(-fill => 'x'); MainLoop; defined $selection and print "'$selection' was selected\n";

In reply to Re^4: Writing my first PERL/Tk megawidgit by tybalt89
in thread Writing my first PERL/Tk megawidgit by Anonymous Monk

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2021-11-28 12:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found