#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Text; my $top = MainWindow->new; my $text = $top->Text->pack(-expand => 'yes', -fill => 'both'); my $menu = $text->menu; add_my_menu_item($menu, 'bogus', $text); $top->configure(-menu => $menu); MainLoop; sub add_my_menu_item{ my ($menu, $name, $widget) = @_; my $entry = $menu->Cascade( -label => $name); map ( $entry->command ( -label => $_, -command => [sub {$widget->insert('insert', $_[0])}, $_], ) (qw/1 2 3 4 5/) ); }