Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Perl/Tk BrowseEntry delete method [request for example]

by scopey (Novice)
on Oct 15, 2008 at 17:05 UTC ( [id://717274]=perlquestion: print w/replies, xml ) Need Help??

scopey has asked for the wisdom of the Perl Monks concerning the following question:

Could anyone supply example code for BrowseEntry's 'delete' method? I'm trying to use a "Delete" button widget to invoke the delete method on the current selection. Another way to describe my problem: how could BrowseEntry, it's delete method, it's -browse2cmd option and some Delete button all work together? Sorry if this sounds vague, I'm a Tk newbie. Thank you!
  • Comment on Perl/Tk BrowseEntry delete method [request for example]

Replies are listed 'Best First'.
Re: Perl/Tk BrowseEntry delete method [request for example]
by zentara (Archbishop) on Oct 15, 2008 at 17:36 UTC
    I would probably go the route of manipulating the -choices array.
    #!/usr/bin/perl -w use strict; use Tk; use Tk::BrowseEntry; my $mw = MainWindow->new(); my $sel = ''; my @choices = qw(1 2 3 4 5 6 7); my $mb; #declare it first so can call it in callback $mb = $mw->BrowseEntry( -label => 'List One', -choices => \@choices, -variable => \$sel, -browsecmd=>sub{ #print "@_\n"; my $selected = $_[1]; #print "$selected\n"; @choices = grep { $_ ne $selected } @choices; $mb->configure(-choices => \@choices); # print "@choices\n"; } )->pack(); MainLoop;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Perl/Tk BrowseEntry delete method [request for example]
by thundergnat (Deacon) on Oct 15, 2008 at 17:54 UTC

    Or, you could manipulate the listbox directly using Subwidget.

    use strict; use warnings; use Tk; use Tk::BrowseEntry; my $var; my $mw = MainWindow->new; my $frame = $mw->Frame->pack; my $be = $frame->BrowseEntry( -label => "Label", -variable => \$var + ); $be->insert( 'end', "opt$_" ) for ( 0 .. 20 ); $be->pack( -pady => 5 ); my $lb = $be->Subwidget('slistbox'); my $bu = $frame->Button( -text => 'Delete Selected', -command => sub { $be->delete( $lb->curselection ) if $lb->curselection; $var = ''; }, )->pack( -pady => 5 ); MainLoop;
      Hey, thanks thundergnat. I didn't know about the Subwidget function of the tk::browseentry. It wasn't obvious to me from the documentation. I must have skimmed over a critical part and missed it. That lets me use the browse2cmd option and get the curselection() with the regular listbox function. I'm not a newbie anymore, but I've still got a lot to learn about the perl infernals. Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://717274]
Approved by Narveson
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found