#!/usr/bin/perl use warnings; use strict; #set up main window display use Tk; my $mw = new MainWindow(-title => 'PopUp'); my @buttons = qw(A B C D E F G); #popup menu set up my $popupmenu = $mw->Menu(-tearoff => 0); foreach my $bt (reverse @buttons){ $popupmenu->insert(0, 'command', -label => $bt, #-command => [sub {print $popupmenu->cget('text') ."\n"}], -command => [sub {print $bt ."\n"}], ); } $mw->bind("" => sub {$popupmenu->Popup(-popover => "cursor", -popanchor => 'nw'), -command => [sub {print "Popup\n"}]}); MainLoop();