Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

FIRST: here is the perl code/widget that I made which works:

#! /usr/pkg/bin/perl use warnings; # use diagnostics; use Tk; use Tk::Entry; unshift (@INC , "/usr/pkg/lib/perl5/site_perl/5.30.0/x86_64-netbsd +-thread-multi/Tk"); unshift (@INC , "/usr/pkg/lib/perl5/vendor_perl/5.30.0/Cache/Memca +ched"); unshift (@INC , "/usr/pkg/lib/perl5/site_perl/5.30.0/Cache"); $mw = MainWindow -> new(); $mw -> title ("Listbox"); @choices = qw /alpha beta charlie delta echo foxtrot hotel india juli +et kilo lima motel nancy oscar papa quebec radio sierra tango uniform + victor whiskey xray yankee zulu oin gloin beorn gandalf elrond eowyn +/; $header_msg = "ENTER a KEY name: "; my ($search , $oldsearch); ##-------------------------------------------------------------------- +------------## &listbox1 (@choices , $header_msg ); ##WORKS!! Make sure the $msg is + last element ##-------------------------------------------------------------------- +------------## MainLoop; sub listbox1 { my(@choices , $header_msg ); $header_msg = pop (@_) ; @choices = @_ ; my $dialog = $mw -> Label (-text => $header_msg ) -> pack( -side = +> "top" ); $dialog = $mw -> Entry (-textvariable => \$search, + ) -> pack ( -side => "top" , -fill => "x" ); $dialog -> bind ( "<KeyPress>" , [\&do_search , Ev ("K" )] ); # $mw = $dialog -> Show(); #HMMMMMM... WORKED; so Show() is unnee +ded? ############## $lb = $mw -> Scrolled ("Listbox" , -scrollbars => "se" , -height => 20 , -selectforeground => 'orange' +, -selectbackground => 'steelbl +ue4' , ) -> pack(-side => "top") ; $lb -> insert ( "end" , sort @choices ); ### MAKE '@choices' the list of $keys my $f = $mw -> Frame( ) -> pack(-side => 'bottom' , -fill => "x" + ) ; $f -> Button ( -text => "QUIT" , -background => 'red', # -relief => 'sunken' -command => sub { ( $mw -> destroy() ) if Tk::E +xists( $mw ); } ) -> pack (-side => 'bottom' , -fill => "x" ); $lb -> bind( '<Double-1>' , \&get_choice ); } ## CLOSE listbox1() ################## sub get_choice { my $mychoice = $lb -> get( 'active'); print "\$mychoice = : $mychoice\n\n "; } sub do_search { my ($entry , $key) = @_; return if ( $key =~ /backspace/ ); return if ( $oldsearch eq $search ); my @list = $lb -> get(0 , "end"); foreach ( 0 .. $#list ) { if ($list [$_] =~ /^$search/ ) { $lb -> see($_); $lb -> selectionClear( 0 , "end" ); $lb -> selectionSet ($_); last; } } $oldsearch = $search; } ## CLOSE do_search()

WHAT I like about it is it sticks the vars in a listbox with a slider. It also searches. Type in the first letter(s) and it takes you to the matching string. I can see uses elsewhere for such a thing. In this case it is for choosing hash-keys so I can delete Cache::Cache entries/elements
I am curious: Why isnt there a megawidget repository somewhere?


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

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2020-10-20 12:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (210 votes). Check out past polls.

      Notices?