Hi Monks,
I am trying to delete a menu item from the menu, but unable to do that. In the below code, I want to delete "Name" Option when clicked on the Delete btn from the Main menu. Please let me know how to delete the menu items (Name, Website, Email) one by one when clicked on Delete option at run time.
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"); my $Btn2 = $insert -> command(-label =>"Website"); my $Btn3 = $insert -> command(-label =>"Email"); $others-> command(-label => "Delete", -underline=>0, -command=>sub {delete_menu();} ); MainLoop; sub delete_menu { $Btn1-> delete(0); }
But i am reveiving the below error message
Tk::Error: Can't locate object method "delete" via package "Tk::Menu:: +Button"

In reply to Deleting Menu Item from Menu by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.