Hi Christopher,
thank you, as always, for your insights. Here are the two screenshots:
script
[image: script.png]
executable launched from the Terminal (not inside an App)
[image: executable.png]
Both generated with the following script:
use Tcl::pTk;
my $mw = MainWindow->new();
my $TextWidget = $mw->Scrolled('Text', -scrollbars=> 'ose', -height=> 3,
-wrap=>'word')->pack(-side=>'top', -expand => '1',-fill => 'both',
-padx=>6);
PupupEnterField($mw, $TextWidget);
MainLoop;
sub PupupEnterField{
my ($mw, $obj) = @_;
my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[
[command=>"MY LABEL", -command=>[sub {StartSub()}, $obj,]],
]);
$obj->menu($menu);
$obj->bind('<2>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]);
return $obj;
}
I solved my problem with the following workaround:
my $foregroundColorMenu='black';
#reading macOS setting
eval{
our $tk_dark = $int->Eval('exec defaults read -g AppleInterfaceStyle');
};
#adapting font of menu/popups depending on Dark/Light UI
if ($tk_dark eq 'Dark'){
$foregroundColorMenu='white';
}
#then adding "-foreground=>$foregroundColorMenu" to all my menus presenting
the color problem
PS: note the use of eval, as the returned state of the function to read the
Dark/Light mode can return "Dark" or die if no value can be read (which
means it is Light)
Not elegant, but at least my application works fine in Dark mode.
Best,
Welle
Am Fr., 10. Mai 2019 um 11:29 Uhr schrieb Christopher Alexander Chavez via
RT <bug-Tcl-pTk@rt.cpan.org>:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=129505 >
>
> This strongly resembles the issue in #125049, however I never suspected
> that
> issue to only appear depending on whether the program is run from a script
> or
> an app. I've only ever run Tcl::pTk from a script, and am not familiar with
> packaging in an app bundle or why that would partially affect the
> appearance. I
> am likely confused on what exact difference is happening in each case; if
> you
> could provide screenshots, that would be handy. I'm aware it's possible
> for an
> app bundle to force enable/disable dark mode (Info.plist?), but am not
> aware
> that that is something you have done for your app. Setting light mode in
> System
> Preferences may make the issue not noticeable; but if the menu entry's
> text is
> dark when highlighted/hovered over, then the issue is technically still
> present.
>
> I use dark mode, but I am not caught up on the changes recently made by Tk
> to
> support it. The macosx/README file in Tk 8.6.9 says that two new virtual
> events
> <<LightAqua>> and <<DarkAqua>> were added to allow handling changes in
> appearance. It is also possible to query the current appearance via
> AppleScript
> (e.g. using the osascript system command), but I would not be surprised if
> there is now an even easier way via Tk.
>
> But from what I have investigated for #125049, I don't believe knowing the
> current light/dark mode is what should be used to resolve this issue. The
> cause, as I currently understand, is that some of the code Tcl::pTk had
> borrowed from Perl/Tk sets default colors for child widgets. But this code,
> which predates Tk Aqua, uses hardcoded colors, and results in some menu
> widgets
> always having entries with black text, which become illegible for the
> dark-background menus in recent macOS versions. Ideally, the colors should
> be
> unset by default; that way, macOS' window manager automatically picks the
> appropriate, legible color. Unfortunately I still have not figured out how
> to
> fix this issue, even though it was one of the first issues I identified
> when I
> began using Tcl::pTk over a year ago.
>
>