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

Re: data structure problem

by kcott (Chancellor)
on Nov 08, 2012 at 06:36 UTC ( #1002824=note: print w/replies, xml ) Need Help??

in reply to data structure problem

G'day perltux,

I was thinking of a hash before I'd even read as far as %hash=(preset=>\@preset, ....

Here's a bare-bones (but working) solution that doesn't use the -choices option. First, a few notes:

  • The -browsecmd callback is passed the widget as the first argument. As I haven't needed that, you'll see undef in a few places. You may need to change that.
  • I made some decisions about display defaults: you may want to make changes here also.
  • As I was uncertain what some of the terms you used referred to, my choices for variable names may be less than meaningful.

Here's the code:

#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my %choices = ( preset => [ qw{tom snare metal analog} ], card1 => [ qw{mellowstr brightstr string3} ], ram => [ qw{acoustic rock bass jazz strato distorted} ], ); my @list_order = qw{preset card1 ram}; my ($current_list, $current_choice); my $mw = MainWindow->new(); my $be_F = $mw->Frame()->pack(); my $ex_F = $mw->Frame()->pack(); my $list_BE = $be_F->BrowseEntry( -variable => \$current_list, -browsecmd => \&update_choices, )->pack(-side => 'left'); my $vary_BE = $be_F->BrowseEntry( -variable => \$current_choice, -browsecmd => \&make_choice, )->pack(-side => 'left'); for (@list_order) { $list_BE->insert(end => $_); } update_choices(undef, $list_order[0]); $ex_F->Button(-text => 'Exit', -command => sub { exit })->pack(); MainLoop; sub update_choices { my (undef, $list) = @_; $current_list = $list; $current_choice = $choices{$list}[0]; $vary_BE->delete(0 => 'end'); for (@{$choices{$list}}) { $vary_BE->insert(end => $_); } return; } sub make_choice { my (undef, $choice) = @_; $current_choice = $choice; return; }

-- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002824]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2018-06-21 12:51 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.