in reply to Tk menu Apple macOS

I don't have an answer for you but I can confirm what you're seeing. I also ran some additional tests. I'm using: macOS Sierra 10.12.5; Perl 5.28.0; Tk 804.034; XQuartz 2.7.11; and, xorg-server 1.18.4.

Firstly, for all tests, I wrapped the code you posted in:

#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow::->new(); ... MainLoop;

[It's best to show code that can be run directly. It makes it easier for us to test. It also means that a potential problem, in the code you haven't shown, can be detected. SSCCE has more about this.]

With your code, I see a ".apple" menu button which has an empty dropdown list. The system (apple-icon) menu is unchanged.

I added this line (after "my $applemenu = ..."):

$applemenu->command(-label => 'Hello', -command => sub { print "Hello\ +n" });

The ".apple" dropdown list now has this item which works as expected. Again, the system (apple-icon) menu is unchanged.

I also tried without the toplevel:

my $menubar = $mw->Menu(-type => 'menubar'); ... $mw->configure(-menu => $menubar);

This also works for the ".apple" menu; but the system (apple-icon) menu is still unchanged.

I'll front-page your post to give it a wider audience as I'd anticipate reduced attendance over the next few days. I'm also personally interested in an answer to this. [Update: haukex front-paged it while I was composing my reply.]

Finally, just as a side note, Perl's Tkx and Tk are both based on tcl/tk. Tkx is just a thin wrapper around it. Tk uses code based on it; for example, see the first line of the Tk::Menu source:

# Converted from menu.tcl --

Although both have superficial similarities in various places, they are quite different. As a quick example:

$mw->Button(...)->pack; # Tk $mw->new_button(...)->g_pack; # Tkx

— Ken

Replies are listed 'Best First'.
Re^2: Tk menu Apple macOS
by chrstphrchvz (Scribe) on Jan 18, 2019 at 20:53 UTC

    Perl/Tk cannot access the native menu bar on modern macOS (i.e. OS X), the main reason being that it still requires XQuartz, and anything run from XQuartz has no knowledge of nor access to the Mac menu bar. The documentation for Perl/Tk's Tk::Menu is quite old, and was likely adapted from whichever historical version of Tcl/Tk it's based on. So the Apple menu it's referring to is likely the one from classic Mac OS 9 and earlier, i.e. pre-Mac OS X.

    To clarify, .menubar.apple refers to the "application menu", the one with the currently-focused program's name. The "Apple menu" (the one with the Apple logo) is off-limits to programs.

    Tcl/Tk wrappers for Perl (Tkx, Tcl::Tk, and Tcl::pTk) should be able to use the Mac menu bar and its application menu on OS X, as long as Tk Aqua is used rather than Tk for X11. For this I would refer to the up-to-date Tcl/Tk documentation on "Special Menus in Menubars", as well as TkDocs' entry on Platform Menus which even has Tkx syntax examples.

    As the co-maintainer of Tcl::pTk, I wish I could say I knew how to use the Mac application menu, but unfortunately I have not yet had any success…

      ++ Thanks for the detailed information on this. I posted "I'm also personally interested in an answer to this.", so your response is very helpful.

      — Ken

Re^2: Tk menu Apple macOS
by Anonymous Monk on Dec 23, 2018 at 10:26 UTC

    A couple of thoughts. In the Tkx example the line that stroke my ears was:

    $appmenu = Tkx::widget->new(Tkx::menu($m->_mpath . ".apple"));

    This seems to create a new menu item with a specific name given by appending 'apple' to the widget's name ($m->_mpath), only after this step it creates a cascade item. $m->_mpath doesn't seem to be Tk code, however Tk knows $widget->PathName which may be (?) a substitution for it. I think the key is around this line. We possibly need a way to set the name of the widget like above. The -label doesn't seem enough.

    PS: Actually I am accessing tcl/tk with Tcl::Tk and/or tcl::pTk (which are great to avoid X11 and have a much much nicer looking GUI). However, this shouldn't make a big difference, at least not at this stage of general understanding.