Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Combo box linked with another combo box

by Selvakumar (Scribe)
on Feb 19, 2013 at 15:22 UTC ( #1019588=perlquestion: print w/ replies, xml ) Need Help??
Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have a combo box having one set of details and i need to show related list to another combobox. I need to show from the list when i select "colors" i need to show colors details in the another combobox and the same should change if i select "fruits". Please suggest.

use strict; use warnings; use Tk; use Tk::BrowseEntry; my $var; my $mw = tkinit; my $widget = $mw->BrowseEntry( -label => 'Select the Journal Name:', -variable => \$var, -state => 'normal', -choices => [qw(Color Fruits)], #-width => 45 )->pack( -side => 'top', -pady => '10', -anchor => 'w'); my $widget1 = $mw->BrowseEntry( -label => 'Select the Journal Name:', -variable => \$var, -state => 'normal', -choices => [qw(White Red)], #-width => 45 )->pack( -side => 'top', -pady => '10', -anchor => 'w'); MainLoop();

Comment on Combo box linked with another combo box
Download Code
Re: Combo box linked with another combo box
by Anonymous Monk on Feb 19, 2013 at 15:33 UTC

    Please suggest.

    well, use a callback, update choices in callback

Re: Combo box linked with another combo box
by zentara (Archbishop) on Feb 19, 2013 at 17:12 UTC
    Here is a way using the browsecommand method of the BrowseEntry and using a hash to store the values.
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $var; my $var1; my @fruits = qw( apple orange bananna grape); my @colors = qw( red orange green purple); my $widget1; # declare here so you can modify it # from first $widget my %options; $options{'Fruits'} = \@fruits; $options{'Colors'} = \@colors; #print "@{$options{'Fruits'}}\n"; my $mw = tkinit; my $widget = $mw->BrowseEntry( -label => 'Select the Journal Name:', -variable => \$var, -state => 'normal', -choices => [qw(Colors Fruits)], -browsecmd=>sub{ #print "@_\n"; my $selected = $_[1]; print "$selected\n"; $widget1->configure( -choices => $options{$var}, ); $mw->update; } )->pack( -side => 'top', -pady => '10', -anchor => 'w'); $widget1 = $mw->BrowseEntry( -label => 'Select:', -variable => \$var1, -state => 'normal', -choices => $options{$var}, #-width => 45 )->pack( -side => 'top', -pady => '10', -anchor => 'w'); MainLoop();

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-12-18 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (48 votes), past polls