11

I have a problem with the support of Dark Mode on MacOS in python Tkinter. I used python 3.6 with ActiveTlc 8.5 and the Dark Mode works fine, the window titlebar was dark, it's fine for me... but there were some problems with the <MouseWheel> support, then I upgraded python to 3.7.1 and the version of tlc is updated to 8.6.

But now the Dark Mode didn't work, and it's strange, why this is happening?

This is an example code:

from tkinter import *

if __name__ == '__main__':
    root = Tk()
    hero_text = Label(root, fg='white', bg='black', text='HERO TEXT')
    hero_text.grid(row=0, sticky=N+W)
    print(root.tk.exprstring('$tcl_library'))
    print(root.tk.exprstring('$tk_library'))
    root.mainloop()
Rarblack
  • 4,559
  • 4
  • 22
  • 33
  • 3
    You're lucky it's just the dark mode. On my system TK applications just show empty, black windows. I would recommend switching to a more modern toolkit like GTK+ 3 or Qt 4. – Bachsau Dec 08 '18 at 02:38
  • 2
    @Bachsau This issue has been fixed in 8.6.9 according to tk developers https://core.tcl.tk/tk/tktview?name=821dbe47e1 – mister_potato Dec 28 '18 at 19:27
  • 2
    This post can help if someone on Mac wants Mojave Dark Mode on Tkinter applications https://stackoverflow.com/questions/55483507/how-to-get-a-black-file-dialog-box-using-tkinter-on-mac-os – Saad Apr 20 '19 at 17:32
  • 2
    You can fix this issue by installing the newest python. – Andy Zhang Mar 19 '21 at 12:11

2 Answers2

1

I also faced this kind of problem, I think you should try this

from tkinter import *

if __name__ == '__main__':
       root = Tk()
       root.configure(bg="black")
       hero_text = Label(root, fg='white', bg='black', text='HERO TEXT')
       hero_text.grid(row=0, sticky=N+W)
       print(root.tk.exprstring('$tcl_library'))
       print(root.tk.exprstring('$tk_library'))
       root.mainloop()
Aninet
  • 11
  • 3
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 03 '22 at 12:31
0

Using the base tkinter module, there is no way to automate dark mode without another module like subprocess. I recommend you add a setting for dark mode, but if you want it to still be automated here is the code to do it:

from tkinter import *
import subprocess

def check_appearance():
   cmd = 'defaults read -g AppleInterfaceStyle'
   p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                     stderr=subprocess.PIPE, shell=True)
   if bool(p.communicate()[0]):
      return "black"
   else:
      return "white"


win = Tk()
win.configure(bg=check_appearamce())

win.mainloop()
AntXD
  • 23
  • 6