Here is the code that I came up with a few hours after posting, mostly cribbed from trolling the web. I have it in a .pm file:
use warnings ; use strict ; use Tk ; use Tk::NoteBook ; my $popup_menu_items = [ [Button => "Close", -command => \&popup_close], [Button => "Other", -command => \&popup_other] ] ; my $tabs ; my $popup_menu ; sub sk_notebook_add { my $MW = shift ; $tabs = $MW->NoteBook()->pack( -fill=>'both', -expand=>1 ); $popup_menu = $tabs->Menu( -menuitems => $popup_menu_items, -tearo +ff => 0 ) ; $tabs->bind( "<Button-3>" => [ \&popup_spot, Ev('X'), Ev('Y') ] ) +; return $tabs ; } my $popup_tab_name ; sub popup_spot { my $x = $_[1] - $tabs->rootx ; my $y = $_[2] - $tabs->rooty ; $popup_tab_name = $tabs->identify( $x, $y ) ; $popup_menu->Popup( -popover => "cursor", -popanchor => 'nw' ) if( + $popup_tab_name ) ; } sub popup_close { $tabs->delete( $popup_tab_name ) ; } sub popup_other { print "name = $popup_tab_name\n" ; } 1 __END__
I have only been programming Perl for a few weeks, so I am not sure what correct style is, but the 'global' variables in the module bother me. I am not sure how else to hand the appropriate widget to the popup subroutines, or even if having a cute way to do so is good Perl.

Brian


In reply to Re^2: Popup Menus on Tk::Notebook tabs by skewray
in thread Popup Menus on Tk::Notebook tabs by skewray

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.