The following code creates a menu list called "User Selection" with four menu items: "Save", "Save As", "Load, and "Load From":
my $userselectedmenuitems = [
[ 'command' , 'Save', -command => \&saveUserSelection ]
[ 'command' , 'Save As', -command => \&saveUserSelectionAs ]
[ 'command' , 'Load', -command => \&loadSelectionsFromDefaultXMLFile ]
[ 'command' , 'Load From', -command => \&loadSelectionsFromUserSpecifiedXMLFile ] ;
my $userselectedmenu = $menubar->cascade (
-label => 'User Selection',
-tearoff => 0,
-menuitems => $userselectedmenuitems,
) ;
Now, the following code will cause the entire menu list to be disabled:
$userselectedmenu->configure(-state => 'disable');
However, that's not what I want. I want to disable only one entry in the list (specifically the "Save" entry). How do I do that?
I saw online that many examples refer to the function "entryconfigure". However, when I run this code:
$userselectedmenu->entryconfigure('Save', -state => 'disable');
I get the following error message:
Can't locate object method "entryconfigure" via package "Tk::Menu::Cascade" at [line number]
Disclaimer: I apologize if this code needs some massaging to be reproducible, I have to transcribe code to this computer by hand.
You first need entrycget
to get the menu, then you can use entryconfigure
to disable its item:
$menubar->entrycget('User Selection', '-menu')
->entryconfigure('Save', -state => 'disabled');