如何在Mac OS上使用Tkinter获得黑色文件对话框? [英] How to get a black file dialog box using Tkinter on Mac OS?

查看:143
本文介绍了如何在Mac OS上使用Tkinter获得黑色文件对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个黑色文件对话框(Mac OS暗模式).我正在使用Tkinter文件对话框模块(import tkinter.filedialog).

I'm trying to achieve a black file dialog box (Mac OS dark mode). I'm using Tkinter filedialog module (import tkinter.filedialog).

  • 莫哈韦沙漠(10.14.4)暗模式
  • Python 3.6.8
  • Tcl/Tk 8.6.8

当我从其他任何应用程序打开文件对话框时,它们具有黑色背景,但是当我从tkinter.filedailog中打开文件对话框时,它们具有默认白色背景.

When I open file dialog from any other app they have black background but when I open it from tkinter.filedailog they have default white background.

这是Tkinter打开的文件对话框的图像:

Here is the image of file dialog opened by Tkinter:

从其他位置打开时,Mojave暗模式支持的黑色文件对话框:

Black file dialog supported by Mojave dark mode when opened from elsewhere:

如果可以通过Tkinter获取黑色文件对话框,请帮助我,我真的想要黑色对话框.

If there is any way to get the black file dialog box with Tkinter, Please help me I really want the black dialog box.

sample.py

import tkinter.filedialog as _FD

_Master = _FD.Tk()
_Master.withdraw()

from kivy.core.window import Window as _kivy_window

class Open(_FD.Open):
    def __init__(self, multiple=False, **options): 
        if multiple: options["multiple"]=1
        super(Open, self).__init__(**options)

    def show(self, **options):
        s = super().show(**options)
        _kivy_window.raise_window()
        return s

if __name__ == "__main__":

    from kivy.app import App
    from kivy.uix.button import Button
    _kivy_window.size = (250, 250)

    class TestApp(App):
        def open(self, *a):
            s = Open(multiple=True)
            s = s.show()
            if s: print(s)

        def build(self):
            return Button(text='Hello World', on_release=self.open)

    TestApp().run()

推荐答案

解决方案

可能的问题不会让您在Tkinter GUI上获得适当的Mojave Dark Mode支持.所有这些都在我的Mac上,在每个系统上可能都不同.

Solution

Possible issues that won't let you have proper Mojave Dark Mode support on Tkinter GUI. All of these were are on my Mac it could different on every system.

我正在使用MacOS Mojave 10.14.4版本

I'm using MacOS Mojave version 10.14.4

默认情况下,暗模式并不适用于所有应用程序,例如第三方和不受信任的开发人员的某些应用程序. 我们仍然可以为那些应用程序实现暗模式",但是并不是每个应用程序都能正常运行,也许这就是为什么它不是该设置中的一个选项的原因.

By default the dark mode doesn't applies to every applications like some apps that are third party and from untrusted developer. We can still achieve Dark Mode to those apps, but not every app will work properly maybe that's why it is not an option in the setting.

如果您不确定要使用命令行,则可能不应该这样做.

  1. 启用黑暗模式,然后在终端中运行此命令:

  1. Enable the Dark Mode and then run this command in terminal:

defaults write -g NSRequiresAquaSystemAppearance -bool No

注意::是"表示对所有窗口禁用,否"表示对所有窗口启用.

Note: "Yes" means disable to all windows and "No" means enable to all.

还原为默认设置.

 defaults delete -g NSRequiresAquaSystemAppearance


步骤2

对于Anaconda

如果您使用Anaconda,则只需执行第一步即可在所有应用程序上获得黑暗模式,然后从命令行将Tcl/Tk更新为8.6.9. (更多详细信息)


Step 2

For Anaconda

If you use Anaconda then you just need to perform 1st Step to get the Dark Mode on all apps then update Tcl/Tk to 8.6.9 from command line. (More Details)

conda install -c conda-forge tk 
conda install -c conda-forge/label/gcc7 tk 
conda install -c conda-forge/label/broken tk 
conda install -c conda-forge/label/cf201901 tk

结果

解决第一个问题后,如果您使用的是Tcl/Tk 8.6.8,则将在Tkinter上获得暗模式",但在tkinter窗口上获得黑屏.

After solving the first issue you will get Dark Mode on Tkinter but black screen on the tkinter window if you have Tcl/Tk 8.6.8.

示例图片

此问题已在Tcl/Tk 8.6.9中修复,但由于python.org尚未更新,还提供了自己的Tcl/Tk 8.6.8私有副本.他们不查找或使用Tcl/Tk的任何第三方或系统副本(更多详细信息).因此,如果您考虑从第三方安装它,我们将浪费时间.

This problem has fixed in Tcl/Tk 8.6.9 but as python.org have not updated it and also supply their own private copies of Tcl/Tk 8.6.8. They do not look for or use any third-party or system copies of Tcl/Tk(More Details). So it'll we be waste of time if you thinking to install it from third parties.

我测试了 Python 3.7.2rc1 ,它内置于Tcl/Tk 8.6.9可以在Mojave暗模式下很好地工作,但是由于在Tk 8.6.9.1中发现了一些退化,他们将已发布的python.org 3.7.2 macOS安装程序恢复为Tcl/Tk 8.6.8.

I tested Python 3.7.2rc1 which is built in Tcl/Tk 8.6.9 and it works well with Mojave Dark Mode but due to some regressions found in Tk 8.6.9.1 they reverted the released python.org 3.7.2 macOS installers back to Tcl/Tk 8.6.8.

示例图片

这篇关于如何在Mac OS上使用Tkinter获得黑色文件对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆