use warnings; use strict; use Tk; my $mw = MainWindow->new; my $text = $mw->Text()->pack; add_edit_popup($mw, $text); MainLoop; sub add_edit_popup { my ($mw, $obj) = @_; my $menu = $mw->Menu( -tearoff => 0, -menuitems => [ [ Cascade => 'Export/Print', -tearoff => 0, -menuitems => [ [ Button => 'MS Word', -command => sub{export_word()} ], [ Button => 'MS Excel', -command => sub{export_html()} ], ], ], [ Cascade => 'Import', -tearoff => 0, -menuitems => [ [ Button => 'MS Word', -command => sub{import_word()} ], [ Button => 'MS Excel', -command => sub{import_html()} ], ], ], ] ); $obj->menu($menu); $obj->bind('<3>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]); return $obj; }