How to get a black file dialog box using Tkinter on Mac OS?

前端 未结 2 1339
清歌不尽
清歌不尽 2020-12-03 16:21

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.1
相关标签:
2条回答
  • 2020-12-03 17:11

    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:

    I am using OSX Dark Mode though...

    0 讨论(0)
  • 2020-12-03 17:18

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

    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

    0 讨论(0)
提交回复
热议问题