Peeking at the currently selected option in Tk::Optionmenu

A

Alexander Farber

Hi,

I have a long scrolled list with a "Save"-button on the bottom.
Each row of the list contains an Optionmenu and an "Info"-button:

my $option = $frame->Optionmenu(-options =>
[
[ "not selected", undef ],
map({ [$module->{vhash}->{$_}, $_] }
@{$module->{vlist}})
],
-variable => \$module->{selected})
->grid(-row => $row,
-column => 2,
-sticky => 'nsew');
$option->setOption($module->{vhash}->{$selected}, $selected)
if $selected;

$frame->Button(-text => 'More info...',
-command => [ \&ShowInfoWindow, $top, $name ],
)->grid(-row => $row,
-column => 3);

I'd need to pass the currently selected option in
the $option above to the button's callback ShowInfoMenu().

So that a user would select an option in the Optionmenu,
click the "More info..." button, read the information
for exactly that selected option and then maybe change
his mind and select some other option before finally clicking
the "Save" button.

So is there a way to get that through the $option please?

Regards
Alex
 
P

Paul Lalli

Alexander said:
I have a long scrolled list with a "Save"-button on the bottom.
Each row of the list contains an Optionmenu and an "Info"-button:

my $option = $frame->Optionmenu(-options =>
[
[ "not selected", undef ],
map({ [$module->{vhash}->{$_}, $_] }
@{$module->{vlist}})
],
-variable => \$module->{selected})
->grid(-row => $row,
-column => 2,
-sticky => 'nsew');
$option->setOption($module->{vhash}->{$selected}, $selected)
if $selected;

$frame->Button(-text => 'More info...',
-command => [ \&ShowInfoWindow, $top, $name ],
)->grid(-row => $row,
-column => 3);

I'd need to pass the currently selected option in
the $option above to the button's callback ShowInfoMenu().

So that a user would select an option in the Optionmenu,
click the "More info..." button, read the information
for exactly that selected option and then maybe change
his mind and select some other option before finally clicking
the "Save" button.

So is there a way to get that through the $option please?

Perhaps I am not understanding. You define your Optionmenu with a
-variable tag, so that $module->{selected} will contain to the
currently selected value of the Optionmenu. Is there some reason you
cannot pass a reference to this variable into your callback?
(Obviously, it's important that a reference be passed, not the value of
the variable at the time the callback is defined).

If I'm missing something, please help me understand your problem.

Also, it is possible you might be able to get better help by posting to
the Tk-specific newsgroup comp.lang.perl.tk

Paul Lalli
 
A

Alexander Farber

I'm sorry - nevermind. I had a problem with a closure.

By the way I think passing $module->{selected} like
below wouldn't work. I had to introduce another hash key
to save the currently selected option in the optionmenu...

Regards
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top