In the case where I needed this, I was attaching a submenu for suggestions while adding live spelling check to a Tk::Text widget. The code is basically a first draft of the concept as part of one of my personal "toy" projects. Here are some pieces:

my $main_text_field = $top->Text(-width => 132, height => 24, -setgrid => 1, -wrap => 'word'); my $main_text_field_spelling_menu = $main_text_field->menu->Menu(-tear +off => 0); $main_text_field_spelling_menu->configure (-postcommand => [\&post_suggestion_menu, $main_text_field, $main_text_field_spelling_menu]) +; $main_text_field->menu->insert ('View', cascade => -label => 'Respell...', -underline => 0, -menu => $main_text_field_spelling_menu);
sub post_suggestion_menu { my $widget = shift; my $menu = shift; my @wordpos; $menu->delete(0, 'end'); # extract word boundaries where user requested menu into @wordpos if (exists $spelling_suggestions{$word}) { $menu->add(command => -label => $_, -command => [\&replace_word, $widget, @wordpos, $_]) foreach @{$spelling_suggestions{$word}}; } else { $menu->add(command => -label => 'No suggestions.', -state => 'disa +bled'); } }

The -postcommand callback is able to edit the menu before it is displayed, although in my use, I wanted a fully dynamic menu that is rebuilt every time the user (me) asks for it. Note that the menu will be displayed (as far as I know) after -postcommand returns. If you want to prevent displaying the menu at all, you would need to replace the binding that posts the menu.


In reply to Re^3: Tk pop-up if condition is met by jcb
in thread Tk pop-up if condition is met by IB2017

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.