Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Tk Menu Cascade has no delete method?

by zentara (Archbishop)
on Oct 17, 2012 at 17:33 UTC ( #999582=note: print w/replies, xml ) Need Help??

in reply to Tk Menu Cascade has no delete method?

Hi, I'm not very good at the deeply nested menus, but here is a working example. P.S. Also see Deleting Menu Item from Menu
#!/usr/bin/perl use warnings; use Tk; use strict; my $mw = new MainWindow; #Making a text area my $txt = $mw -> Scrolled('Text',-width => 30,-scrollbars=>'e') -> pac +k (); #Declare that there is a menu my $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); my $others = $mbar -> cascade(-label =>"Main", -underline=>0, -tearoff + => 0); my $help = $mbar -> cascade(-label =>"Help", -underline=>0, -tearoff = +> 0); ## Others Menu ## my $insert = $others -> cascade(-label =>"Insert", -underline => 0, -t +earoff => 0); my $Btn1 = $insert -> command(-label =>"Name",-command=>sub{print "2\n +";}); my $Btn2 = $insert -> command(-label =>"Website"); my $Btn3 = $insert -> command(-label =>"Email"); $others-> command(-label => "Delete", -underline=>0, -command=>sub {delete_menu();} ); $help-> command(-label => "Add", -underline=>0, -command=>sub {add_menu();} ); MainLoop; sub add_menu{ # must be cascade, checkbutton, command, radiobutton, or separator $Btn1->parentMenu->add('command',-label => time, -command=>sub{print "3\n";}); } sub delete_menu { print "1\n"; #$Btn1->parentMenu->delete(0); #or $Btn1->parentMenu->delete($Btn1->parentMenu->index($Btn1->[1])); + #or $Btn1->[0]->delete($Btn1->[0]->index($Btn1->[1])); #or $$Btn1[0]->delete($$Btn1[0]->index($$Btn1[1])); # or $insert->menu->delete($insert->menu->index($$Btn1[1])); + }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999582]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2018-04-23 21:43 GMT
Find Nodes?
    Voting Booth?