MK wrote:
>
zentara wrote:
>>
[EMAIL PROTECTED] (MK) wrote:

no matter where i use:

$menu->entryconfigure(#,"disabled);

i get:

Can't locate object method "entryconfigure" via package
"Tk::Menu::Cascade"

unless i use it on a non-existent $menu, in which case i get:

Can't call method "entryconfigure" on an undefined value

Also, if i add a -command in a cascade(), i get no warnings or
complaints but perl ignores the command and simply opens the menu.
I
would like to call a command when a submenu is opened to determine
which entries are available; surely this is possible?

Menu's are a complex nested structure and you need to delve into
it with cget, to get to the right menuitem.

Look at this example:
#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $count = 0;

my $mw = tkinit;

my $menubar = $mw->Menu(-type => 'menubar');
$mw->configure(-menu => $menubar);

my $menu = $menubar->cascade(-label => '~File');
$menu->command(-label => '~New');
$menu->command(-label => '~Open');

$mw->Button(
-text    => 'Push me and look at the menu',
-command => sub {
my $state = ($count++ & 1) ? 'normal' : 'disabled';
$menu->cget(-menu)->entryconfigure(2, -state => $state);
}
)->pack;

MainLoop;
__END__
>
> sorry, zentara, but with my perl 5.8.8 this script first produces:
>
> Bareword "Mainloop" not allowed while "strict subs" in use at
> ./Tkmenuentryconfigure.pl line 25
>
> And even after i delete "use strict" i now get:
>
> Useless use of a constant in void context at ./Tkmenuentryconfigure.pl
> line 25
>
> I presume it did work for you at some point?
>
> I also notice from Tk::Menu "BUGS At present it isn't possible to use
> the option database to specify values for the options to individual
> entries."
>
> I have gotten around this by regenerating the menus with eliminated
> instead of "shaded" entries, but as always anyone who can successfully
> explain these mysteries better to me is very welcome to try ;)

(Please bottom-post your replies so that long threads can remain
comprehensible. Thank you.)

You have 'Mainloop' where Zentara had 'MainLoop'. Perl is case-sensitive
and the two are not interchangeable. It is always best to copy and paste
posted code so that mistakes like this don't happen.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to