Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Confusing behavior from Tk::BrowseEntry

by kcott (Archbishop)
on May 25, 2020 at 00:23 UTC ( [id://11117212]=note: print w/replies, xml ) Need Help??


in reply to Confusing behavior from Tk::BrowseEntry

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-28 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found