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

This question probably should go to the ActiveState forum, but the response rate is much better here! My Tk application runs under Linux, Win32, and OSX. All give the same results except for a right mouse popup menu which is different on all 3.

The code that attaches the menu looks like this:

my $menu = $win->Menu(-tearoff=>0, -menuitems=>[ [qw/command Edit/, -command=>[\&load_in_editor, $created_text, \ +$hold_line]], ]); $created_text->menu($menu); $created_text->bind('<3>', [\&get_text_line, Ev('X'), Ev('Y'), \$h +old_line]);
The get_text_line call will find the line in a scrolled text panel that the cursor is over (the $created_text variable), though that is not the problem as it seems to work in all cases. I've tried changing the button ID <3> to <2> for OSX with no difference!

Anyone have OSX/Tk experience?

Replies are listed 'Best First'.
Re: Tk and right-mouse popup menus under OSX
by lamprecht (Friar) on Feb 14, 2011 at 08:24 UTC

    Did you check the setting of 'Emulate 3-Button Mouse'(or something like that) in your X11 preferences. If this is set, you should get <3> events by pressing 'apple'-<1>:

    chris$ perl -MTk -e'tkinit->bind("<3>",sub{print "3\n"});MainLoop' 3 3

    Cheers, Christoph
      Thanks, that pointed me in the right direction--and sorry I left out a piece of information: I was using the Trackpad, not an actual mouse.

      The fix is to enable "Secondary Click" in the System Preferences (You have an option of left or right corners of the Trackpad). OSX then behaves like Linux (The context menu staus up as long as the right button is held down; releasing the button over a popup menu item activates the item).

      I then belatedly tried the app with an actual mouse and the right button click worked as expected--regardless of the "Secondary Click" setting.

Re: Tk and right-mouse popup menus under OSX
by vkon (Curate) on Feb 14, 2011 at 07:23 UTC
    you haven't showed a piece of code that displays menu.

    what perl version? what tcl/tk version have this OSX?
    'widget' demo that comes with perl/tk - does it have same problem?

      what tcl/tk version have this OSX?

      Isn't that irrelevant for perl/Tk?

        I'm constrained to Perl 5.8.x by ActiveState (they dropped Tk after that). My users need binaries, not command lines and the AS app builder gives me binaries for all platforms (inc AIX, but I ignore that).

        OS wise, Snow Leopard 10.6 is all I have to test against.

        Demo code wise, as far as I can see replacing the context popup menu using the Tk::Text->menu function is documented, but AFAIK, not demonstrated; neither is binding the right mouse button to a menu popup action.

      The menu display code is inbuilt to the Tk::Text widget already (you get a default popup with cut, paste...). The ->menu method allows you to replace the popup menu, but the display code remains in-built. I've re-bound the <3> right-button so I can trap where the where the even happens, turn that into a line number, and pass it to the popup command.
        indeed, I was wondering whether right-click menu of Text widget is actually seen,

        glad that you've resolved your problem.