3

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

  • Mojave (10.14.4) dark mode
  • Python 3.6.8
  • Tcl/Tk 8.6.8

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.

Here is the image of file dialog opened by Tkinter:

#Image1

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

#Image2


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()
Saad
  • 3,340
  • 2
  • 10
  • 32

2 Answers2

5

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

STEP 1: First thing you need to force dark mode to those apps which do not support dark mode officially.

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.

  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.

  2. 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.

defaults delete -g NSRequiresAquaSystemAppearance

STEP 2: How to FIX the black Tkinter window?

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 the 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

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. And also we have to pass foreground = 'black to see the text of Button enter image description here and for some other widgets as well.

conda install -c conda-forge/label/cf202003 tk

Python.org

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.

Sample Image

enter image description here

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. They do not look for or use any third-party or system copies of Tcl/Tk(More Details). 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.

Sample Image

Saad
  • 3,340
  • 2
  • 10
  • 32
1

I'm not a GUI developer, but I'm pretty sure OSX won't let you change the colour of entities such as a dialog window...

If it helps, I ran your code and got the following:

success

I am using OSX Dark Mode though...

justcompile
  • 3,362
  • 1
  • 29
  • 37
  • when I run my code I get a white dialog, I'm using OSX Dark Mode too. Can you explain how you got it right? – Saad Apr 02 '19 at 22:07
  • I found the problem but not sure what the solution can be. The problem is that I’m using python 3.6.7 which uses tcl 8.6.8 and tk 8.6.8 which doesn’t support dark mode with macos though if u have python version below 3.6.5 then it uses tcl 8.5 which does work with Mojave dark mode. I appreciate your help thank you! – Saad Apr 03 '19 at 17:57
  • Pretty sure I was using 3.7.2 – justcompile Apr 03 '19 at 17:57
  • I could be wrong completely but this is the post https://stackoverflow.com/questions/52929744/python-tkinter-not-support-macos-mojave-dark-mode. – Saad Apr 03 '19 at 17:59