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

I would like to be able to know when a menu button has been pressed and the menu is being displayed. I know there is a postcommand feature, but that doesn't help me because it only tells me when the menu goes up and not when it goes down. I want to probably use something like ismapped() from the general widget functions, but I can't figure out how to find the parentid of the menu itself rather than the menu button. Thanks for any help.

Erad

  • Comment on How to tell when menu button menu is up

Replies are listed 'Best First'.
Re: How to tell when menu button menu is up
by Eradicatore (Monk) on Jun 07, 2001 at 02:13 UTC
    I apologize for the vaugeness. I originally posted this under gui q+a and for some reason was assuming questions were ususally about perl/tk.

    Anyway, here is an example of some code:

    #!/usr/local/bin/perl use Tk; my $main = new MainWindow; $help_mb = $main->Menubutton(-text => "Help", -bg => '#bdc4c2', -tearoff => '0', -activebackground => '#bdc4c2', -relief => 'raised', -menuitems => [ [ 'command' => "quit +", "-command" => \&my_ +quit, "-underline" => 0 ] ], )->pack(-side => 'right'); MainLoop; sub my_quit { exit; }
    So what I want to know is when the user clicks on the menu button, and up pops the menu saying "quit", but they haven't clicked it or let go, and the menu is still there, how do I know that? Again, I could use -postcommand to know when the menu appeared, but I would not know when it went away.

    Please let me know if that clarifies the question. Thanks. I suppose I could add some hack where every option in the menu turns off some boolean that was turned on by the -postcommand option, but there should be a much more elegant solution if I could just use ismapped() on the acutal menus widget id I think. ??

    Erad

Re: How to tell when menu button menu is up
by Vynce (Friar) on Jun 07, 2001 at 01:16 UTC

    I think you could use a little clarification in your question here. what kind of menu? what system are you talking about? are you talking about an application menu in a WinX app? a winow menu under KDE? a perl TK app that you wrote yourself? or what? "the general widget functions" in what module? the more you tell us, the more likely we are to understand the problem. the better we understand, the better the answers.

    .