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.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__
Brian
In reply to Re^2: Popup Menus on Tk::Notebook tabs
by skewray
in thread Popup Menus on Tk::Notebook tabs
by skewray
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |