#!/usr/bin/winperl use warnings; use strict; use Tk; my @menu_items = splice @{[get_menu_items()]}, 0, 3; @menu_items = ('None') unless @menu_items; my $mw = MainWindow->new(); $mw->Label(-text => 'Right-click for menu...')->pack(); my $m = $mw->Menu(-tearoff => 0,font => "{arial} 12 {bold}",-menuitems => [ map { [Button => $_, -command => sub { replace($_) }] } @menu_items ]); $mw->bind("" => sub { $m->Popup(-popover => "cursor",popanchor => 'nw') }); $mw->focus(); MainLoop; sub get_menu_items { return qw(); # return qw(Foo Bar Baz); # return qw(Foo Bar Baz Quux Zod Wibble); }