[英]How to get a black file dialog box using Tkinter on Mac OS?
I'm trying to achieve a black file dialog box (Mac OS dark mode).我正在尝试实现黑色文件对话框(Mac OS 深色模式)。 I'm using Tkinter filedialog module (
import tkinter.filedialog
).我正在使用 Tkinter 文件对话框模块(
import tkinter.filedialog
)。
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.filedailog
打开它时,它们具有默认的白色背景。
Here is the image of file dialog opened by Tkinter
:这是
Tkinter
打开的文件对话框的图像:
Black file dialog supported by Mojave dark mode when opened from elsewhere:从别处打开时 Mojave 暗模式支持的黑色文件对话框:
If there is any way to get the black file dialog box with Tkinter
, Please help me I really want the black dialog box.如果有任何方法可以使用
Tkinter
获得黑色文件对话框,请帮助我我真的很想要黑色对话框。
sample.py样本.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()
Possible issues that won't let you have proper Dark Mode support on Tkinter GUI.可能会出现无法让您在 Tkinter GUI 上获得适当暗模式支持的问题。 All of these were are on my Mac it could differ in every system.
所有这些都在我的 Mac 上,每个系统可能会有所不同。
By default, the dark mode doesn't apply to every application like some apps that are third parties and from untrusted developers.默认情况下,暗模式并不适用于所有应用程序,例如某些第三方应用程序和不受信任的开发人员的应用程序。 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.
我们仍然可以为这些应用程序实现暗模式,但并非每个应用程序都能正常工作,这也许就是为什么它不是设置中的一个选项。
If you're not confident in using the command line you probably should not do this.如果您对使用命令行没有信心,您可能不应该这样做。
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.注意: “是”表示对所有窗口禁用,“否”表示对所有窗口启用。
After running the command log out and log back in to notice the changes.运行命令后注销并重新登录以注意更改。
If you want to revert back to default settings, simply delete the NSRequiresAquaSystemAppearance
setting with the following command.如果您想恢复为默认设置,只需使用以下命令删除
NSRequiresAquaSystemAppearance
设置。
defaults delete -g NSRequiresAquaSystemAppearance
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 the command line.如果您使用 Anaconda,那么您只需要执行 1st Step 即可在所有应用程序上获得暗模式,然后从命令行将 Tcl/Tk 更新到 8.6.9。 ( 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
Results结果
UPDATE:更新:
Anaconda has updated Tcl/Tk to 8.6.10 and also added one new command which supports different appearance modes of macOS (dark, light) , which means changing any mode will change the background color of the window and widgets as well but it is a bit glitchy. Anaconda 已将 Tcl/Tk 更新至 8.6.10 并添加了一个支持 macOS 不同外观模式(深色、浅色)的新命令,这意味着更改任何模式都会更改窗口和小部件的背景颜色,但它是一个有点毛病。 And also we have to pass
foreground = 'black
to see the text of Button
而且我们还必须通过
foreground = 'black
来查看Button
的文本 and for some other widgets as well.
以及其他一些小部件。
conda install -c conda-forge/label/cf202003 tk
After solving the first issue you will get Dark Mode on Tkinter but a black screen on the Tkinter window if you have Tcl/Tk 8.6.8.解决第一个问题后,您将在 Tkinter 上获得暗模式,但如果您有 Tcl/Tk 8.6.8,则在 Tkinter 窗口上会出现黑屏。
Sample Image示例图像
This problem has fixed in Tcl/Tk 8.6.9 but as python.org has not updated it and also supplies their own private copies of Tcl/Tk 8.6.8.此问题已在 Tcl/Tk 8.6.9 中修复,但由于 python.org 尚未对其进行更新,并且还提供了他们自己的 Tcl/Tk 8.6.8 私有副本。 They do not look for or use any third-party or system copies of Tcl/Tk( More Details ).
他们不寻找或使用 Tcl/Tk 的任何第三方或系统副本(更多详细信息)。 So it'll be a waste of time if you thinking to install it from third parties.
因此,如果您想从第三方安装它,那将是浪费时间。
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.我测试了内置 Tcl/Tk 8.6.9 的Python 3.7.2rc1 ,它在 Mojave 暗模式下运行良好,但由于在 Tk 8.6.9.1 中发现了一些回归,他们恢复了已发布的 python.org 3.7.2 macOS 安装程序到 Tcl/Tk 8.6.8。
Sample Image示例图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.