Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?

Thanks

Comment on Tk Popup menu
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021230]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-08-28 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls