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

I am trying to create a cascading menu using Perl TK on a Solaris 9 system using Perl 5.8/Tk. The problem I am having is that all my cascaded menues are popping up. What I would like is to have the submenu's popup only when I click on the menu item. Any ideas?? Note--> I have simplified the below code for easier reading. thanks w3ntp
#!/usr/local/bin/perl # ABSTRACT: Perl Shell script to create menu widgets # # use Tk; # # Start the Main program # print "Menu Shortcut Server Ver 1.0, working....\n"; $mw = MainWindow -> new; $mw -> title("NOCMAN Workstation"); $mw -> Frame( -width => 300, -height => 18) -> pack; $mw -> configure( -menu => my $menubar = $mw -> Menu); my $file = $menubar -> cascade(-label => '~File'); my $edit = $menubar -> cascade(-label => '~Edit'); $new = $file ->cascade( -label => 'New'); $new ->command( -label => 'new stuff'); $new ->command( -label => 'more stuff'); $new ->command( -label => 'other stuff'); $file ->command( -label => 'Open'); $file ->command( -label => 'Save'); $file ->command( -label => 'Save as..'); $file ->command( -label => 'Close', -command => \&exit); $edit ->command( -label => 'Open'); $edit ->command( -label => 'Save'); $edit ->command( -label => 'Save as..'); $edit ->command( -label => 'Close', -command => \&exit); MainLoop; exit;

Replies are listed 'Best First'.
Re: How to implement a cascading Menu
by PodMaster (Abbot) on May 11, 2005 at 07:03 UTC
    I am trying to create a cascading menu using Perl TK. The problem I am having is that all my cascaded menues are popping up.
    You only have one cascade menu, and (update:for some reason I don't consider $file/$edit cascade, whoops) it only pops up (reveals the cascade menu) when you mouse over (hilight) the New item in the File menu.
    update: to clarify, when running your program, none of the menus show until I click something, that is, works as expected.
    What I would like is to have the submenu's popup only when I click on the menu item.
    You might be able to do it on unix, see "Cascade Entries" in the Tk::Menu documentation.
    update: To clarify, the $file/$edit menus wait for a mouse click, while $new will show when it's hilighted.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thank you for the reply. We are running the Perl Menu program on a Solaris 9 platform using Perl version 5.8.. Secondly, our menu structure goes to 3 or 4 levels and I do not know how to have it cascade to the next level using a mouse click. It seems to cascade automatically. I am sure this is something simple like adding some option to one of the fields. Any suggestions? I am stuck. thank you very much w3ntp
Re: How to implement a cascading Menu
by zentara (Cardinal) on May 11, 2005 at 10:47 UTC
    I havn't delved much into the inner workings of menus, but I have one observation, which may be a clue. When I run your program, I click on FILE and the new submenu is automatically opened up( which I guess is the problem you describe).

    It looked to me like if there is a submenu, as the first element in the dropdown, it gets automatically selected. If I move the New submenu code, out of the first position, it works fine.

    I would guess that you could find a workaround if you need the $new first in the list, maybe force the default selection to be other than the first. Or just take the easy way out, and put your submenus towards the bottom. More help may be available on comp.lang.perl.tk


    I'm not really a human, but I play one on earth. flash japh