Home > Archive > PerlTk > October 2005 > Another BrowseEntry question: selecting an entry
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Another BrowseEntry question: selecting an entry
|
|
| register_allocation 2005-10-27, 6:59 pm |
| Suppose I have something like this:
my $mw = tkinit;
my @choices = qw(one two three);
my $be = $mw->BrowseEntry(
-label => 'Select',
-state => 'readonly',
-choices => \@choices
)->pack(-side => 'top');
# I want to select one of the choices here
MainLoop;
__END__
I want to programmatically select one of the choices. Is there a
way to do this without using -variable => \@some_reference?
I tried $be->configure(-text => $selection_desired), which works,
but it barfs when I try to change to a different selection :-(
I looked at the documentation, but didn't see anything obvious...
Thanks for any help,
-ra
| |
| Ala Qumsieh 2005-10-27, 6:59 pm |
| register_allocation wrote:
> Suppose I have something like this:
>
> my $mw = tkinit;
> my @choices = qw(one two three);
>
> my $be = $mw->BrowseEntry(
> -label => 'Select',
> -state => 'readonly',
> -choices => \@choices
> )->pack(-side => 'top');
>
> # I want to select one of the choices here
>
> MainLoop;
>
> __END__
>
> I want to programmatically select one of the choices. Is there a
> way to do this without using -variable => \@some_reference?
>
> I tried $be->configure(-text => $selection_desired), which works,
> but it barfs when I try to change to a different selection :-(
>
> I looked at the documentation, but didn't see anything obvious...
.... so look at the source :)
assuming you want to select the second item ('two'). This item has an
index of 1 in the @choices array. So:
my $selIndex = 1; # choice 'two'
$be->Subwidget('slistbox')->Subwidget('listbox')->selectionSet($selIndex);
$be->LbCopySelection;
Again, this is a hack. I think that using -variable => \$your_selection
is the better solution.
--Ala
| |
| Rob Seegel 2005-10-29, 7:56 am |
| This is a shameless plug, but you might consider Tk-JComboBox as an
alternative, it includes a few programmatic ways of accomplishing what
you're looking to do. Admittedly, it is a more heavyweight solution than
BrowseEntry.
Rob
register_allocation wrote:
> I want to programmatically select one of the choices. Is there a
> way to do this without using -variable => \@some_reference?
>
> I tried $be->configure(-text => $selection_desired), which works,
> but it barfs when I try to change to a different selection :-(
>
> I looked at the documentation, but didn't see anything obvious...
>
| |
| Jack D 2005-10-29, 7:56 am |
|
"register_allocation" <register_allocation@lycos.com> wrote in message
news:qd88f.2416$Rl1.601@newsread1.news.pas.earthlink.net...
> Suppose I have something like this:
>
> my $mw = tkinit;
> my @choices = qw(one two three);
>
> my $be = $mw->BrowseEntry(
> -label => 'Select',
> -state => 'readonly',
> -choices => \@choices
> )->pack(-side => 'top');
>
> # I want to select one of the choices here
>
> MainLoop;
>
> __END__
>
> I want to programmatically select one of the choices. Is there a
> way to do this without using -variable => \@some_reference?
Why must you find a different way? It seems a strange request.
-variable does exactly what you need to do - namely "programmatically select
one of the choices"
use Tk;
use Tk::BrowseEntry;
my $mw = tkinit;
my @choices = qw(one two three);
my $be = $mw->BrowseEntry(
-variable=>\$var,
-label => 'Select',
-state => 'readonly',
-choices => \@choices
)->pack(-side => 'top');
# Choose "two"
$var = $choices [1];
MainLoop;
|
|
|
|
|