Next is the subroutine I created, based on the one above, to alter the options. The main changes are that I give the name of the native option menu create rather than its parentand there is a reference to the array of the new options I want.sub native_optionmenu { my($parent, $varref, $command, @optionvals) = @_; $$varref = $optionvals[0]; my $mb = $parent->Menubutton( -textvariable => $varref, -indicatoron => 1, -relief => 'raised', -borderwidth => 2, -highlightthickness => 2, -anchor => 'c', -direction => 'below', ); my $menu = $mb->Menu(-tearoff => 0); $mb->configure(-menu => $menu); my $callback = ref($command) =~ /CODE/ ? [$command] : $command; foreach (@optionvals) { $menu->radiobutton( -label => $_, -variable => $varref, -command => [@$callback, $_], ); } $mb; }
I call this new subroutine with the following.sub update_native_optionmenu_options { my($native_nm, $varref, $command, $ref_optionvals) = @_; my ($menu, $callback); $$varref = $ref_optionvals->[0]; $callback = ref($command) =~ /CODE/ ? [$command] : $command; foreach (@$ref_optionvals) { $menu = $native_nm->cget(-menu); $menu->radiobutton( -label => $_, -variable => $varref, -command => [@$callback, $_], ); } }
I have two problems. The new options are added to the existing options rather than replacing them (and if I call the update subroutineagain the list of options can even longer). I can only ‘select’ one of the original options even though I have moved the cursor over one of the new options and pressed the left mouse button. How can I overcome these issues?update_native_optionmenu_options( $nm_wg, \$nm_string, [sub {print "native om = @_.\n"}, 'First'], \@nm_local_options);
In reply to TK Native Option Menu - Options Update Problems by merrymonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |