Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I have the following quite complex pop-up menu that - for certain geometry-related circumstances - I want to open always "above". The popup menu is attached to an icon.

sub PopupLookup{ my ($mw, $obj) = @_; print "Building popup\n"; my @items('black', 'yellow', 'red'); my $Content11='states'; my $Content12='city'; my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>'Show Menu', -command=>[sub {DialogSettings()}, $obj,]], [ checkbutton => "Show column 1", -variable => \$Content11, -onvalue => '11', -offvalue => '0', -compound => 'left', -command => [ sub { SetView(1) }, $obj ] ], [ checkbutton => "Show column 2", -variable => \$ContentC12, -onvalue => '12', -offvalue => '0', -compound => 'left', -command => [ sub { SetView(2) }, $obj ] ], map ( [radiobutton => " Search in $DBColumn{$_}", -variable => \$DBColumn, -command => sub {print "Setting $_\n"}, -value => $_, ], @items ), [ radiobutton => " Search all languages", -variable => \$DBColumnTo, -value => '0', -command => [ sub { print "Setting search in all\n" }, $obj + ] ], ]); $obj->menu($menu); $obj->bind('<ButtonPress>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]) +; return $obj; }

I could not find any option allowing me this. Have I overlooked something? As an alternative, I looked into Menubutton. Not quite sure as it relates to Menu. Menubutton has a -direction => 'above' option. It seems it cannot be attached to an icon, but I could live with it. I came out with this simple code (partly derived from the widget examples):

sub menbut { my($TOP) = @_; my $menubutton = $TOP->Menubutton(qw/-underline 0 -relief raised/, -text => 'SELECT', -direction => 'above'); my $menu = $menubutton->menu(qw/-tearoff 0/); $menubutton->configure(-menu => $menu); $menubutton->command(-label => "menu: first item", -command => sub {print "You selected the first item from the $pos menu.\n" +}); $menubutton->command(-label => "menu: second item", -command = +> sub {print "You selected the second item from the $pos menu +.\n"}); $menubuttons->pack(); }

However, no matter how hard I try, I cannot put my buttons structure in the script snippet. Any help would be very much appreciated. I know everything is there, but...

Replies are listed 'Best First'.
Re: Tk Menu Menubutton direction
by zentara (Cardinal) on Jan 30, 2019 at 14:22 UTC
    Hi, I'm sorry I don't have an exact answer for you, as my mind is not on Perl these days, but I did see that no one has given you a reply, so here is what I can offer.

    You probably need to make a derived menu widget of your own. See Making a derived Tk::Text object for an example of how to do this with a text widget. Also see Deleting Menu Item from Menu for an introduction to the complexity of the Menu widget's arrays.


    I'm not really a human, but I play one on earth. ..... an animated JAPH