Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Tk Popup menu

by welle (Beadle)
on Mar 01, 2013 at 11:35 UTC ( #1021230=perlquestion: print w/replies, xml ) Need Help??
welle has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I've been using popup menus for a while such as:

sub add_edit_popup { my ($mw, $obj) = @_; my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>'Start Term Info', -command=>[\&get_term_info_from_col_1 +_partial, $obj,]], '', [qw/command Copy/, -command=>['clipboardCopy', $obj,]], [qw/command Paste/, -command=>['clipboardPaste', $obj]], '', [command=>'Select All', -command=>[ sub { $_[0]->selectionRange(0, 'end'); }, $obj, ]], [command=>'Unselect All', -command=>[ sub { $_[0]->selectionClear; }, $obj, ]], ]); $obj->menu($menu); $obj->bind('<3>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]); return $obj; }

I'd like to add a menu entry wiht suboption. In a classical menu, I obtain this with a simple:

my $frame_GUI = $mw->toplevel; my $menubar = $frame_GUI->Menu(-type => 'menubar'); $frame_GUI->configure(-menu => $menubar); my $menu_export_import = $menubar->cascade(-label => '~Import/Expo +rt', -tearoff => 0); my $menu_export = $menu_export_import -> cascade(-label =>"Export/ +Print", -underline => 0, -tearoff => 0); $menu_export->command(-label => 'MS Word)', -command => sub{expor +t_word()}); $menu_export->command(-label => "MS Excel)", -command => sub{expor +t_html()}); my $menu_import = $menu_export_import -> cascade(-label =>"Import" +, -underline => 0, -tearoff => 0); $menu_import->command(-label => 'MS Word)',-command => sub{import_ +word()}); $menu_import->command(-label => 'MS Excel', -command => sub{import +_excel()});

How can use the same structure of menu/submenus in the popup code above?


Replies are listed 'Best First'.
Re: Tk Popup menu
by zentara (Archbishop) on Mar 01, 2013 at 12:42 UTC

      I'm just trying to add a cascade item in my popup menu using the code add_edit_popu

Re: Tk Popup menu
by thundergnat (Deacon) on Mar 01, 2013 at 15:16 UTC

    I must admit, I'm a little puzzled as well. You have all the pieces there, you just need to put them together.

    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; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021230]
Approved by Ratazong
[ambrus]: was this bug: https://rt.cpan. org/Public/Bug/ Display.html?id= 59814
[Corion]: ambrus: Oh - that one would be much harder to automate... The SYNOPSIS section should mostly be a runnable program IMO, but I write only small snippets in my documentation for single functions/methods, and creating the appropriate environment for ...
[Corion]: ... those in an automated fashion seems somewhat hard to me. Although it should do wonders for the test coverage ;)
[haukex]: Corion: I once wrote an automated thingy for that here
[haukex]: here's the code that uses it
[Corion]: haukex: Hmm - maybe I can reuse that. I see that it uses Pod::Parser, which I think was one of the more fragile parsers. But if I'm statically (re)generating the tests instead of doing that "live" on the client/tester machines, that's a much smaller...
[Corion]: ... problem space than trying to cater to all versions of Pod::Parser(s)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2017-02-27 12:20 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (385 votes). Check out past polls.