G'day DcmbrAgnt,

You really haven't shown enough code to be certain; however, I suspect your problem may lie with this:

sub { $midi_indev = $midi_outdev; ...}

The $midi_indev is a package (global) variable. You don't actually use it in the sub where it's assigned a value. As you don't show any code where $midi_indev is also used, I won't speculate further.

You should be using the strict and warnings pragmata: see "perlintro: Safety net".

What you probably need to do is create a reference to $midi_outdev before constructing the Tk::BrowseEntry widget. Then use that reference something like this:

my $midi_outdev_ref = \$midi_outdev; ... -variable => $midi_outdev_ref, ... sub { my $midi_indev = $$midi_outdev_ref; ... }, ...

Here's a very bare-bones example:

#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my @choices = 'A' .. 'Z'; my $picked = $choices[0]; my $picked_ref = \$picked; my $mw = MainWindow::->new(); $mw->BrowseEntry( -variable => $picked_ref, -choices => \@choices, )->pack(); $mw->Button( -text => 'Print Choice', -command => sub { print "Choice: $$picked_ref\n"; }, )->pack(); MainLoop();

This code is fully functional. It always shows 'A' as the initial selection; it always prints the last selected value whenever the "Print Choice" button is used.

"... ALSA MIDI ports, which are being scanned with MIDI::ALSA and put into an array long before the BrowseEntry widget ever gets configured or displayed."

There may also be something wrong about that assertion. Do you know for certain or is that an assumption? Without seeing your code, I can't tell.

If the above suggestions don't help, please create an SSCCE that reproduces your problem. Do keep it short: unless it's relevant, omit anything to do with colours, fonts, justification, and so on.

You might also like to take a look at the Widget Demo. In case you don't know, just type widget on the command line. I can see two examples using Tk::BrowseEntry under Tix Widgets (items 2 & 3).

— Ken


In reply to Re: Confusing behavior from Tk::BrowseEntry by kcott
in thread Confusing behavior from Tk::BrowseEntry by DcmbrAgnt

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, details, 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, summary, 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.