The problem is that the Menu does a grabGlobal somewhere in it's internal code, so you can't leave open menus laying around. Unless that grab is released, you need to deal with it. Popups and Dialogs works that way too.... they do a grab and demand that you deal with it, by clicking a button or whatever releases the grab.

To demonstrate the problem, look at the following and google for "perl tk grabGlobal". You can do mouse grabs, keyboard grabs, or global grabs. Your focus cannot shift until the grab is released.

There may be a clever trick to override it, but I don't know it offhand.

I would try something like $top->bind( '<Leave>',sub { $top->grabRelease } );

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; # the window must be mapped for a global grab # so make a 1 pixel window in lower right corner # for invisible grabs $mw->geometry('200x200+50+50'); $mw->overrideredirect(1); $mw->bind("<Key>", [ \&process_key_press , Ev('K') ] ); $mw->bind("<KeyRelease>", [ \&process_key_release , Ev('K') ] ); $mw->Label(-text=>"Press escape to exit")->pack(); $mw->after(100,sub{$mw->grabGlobal;}); $mw->focusForce; MainLoop; sub process_key_press{ my ($caller, $key) = @_; print "Press $key\n"; if ($key eq 'Escape'){exit} } sub process_key_release{ my ($caller, $key) = @_; print "Release $key\n"; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

In reply to Re^3: Problem with multiple windows and drop down menus by zentara
in thread Problem with multiple windows and drop down menus by bobbob911

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.