How can I match the background colors for the frame in a laptop for ttk / tkinter on mac?

While working with the Tkinter + ttk GUI on my Mac, I noticed a problem with the background colors and Notebook widgets. When you add a tab ttk.Frameas a tab, the ttk.Notebookdisplayed frame background does not match the "insert" background for the Notebook tab.

How can I match the color ttk.Frameto the surrounding background color without hard coding, which will look strange for non-Mac users?

example of frame background mismatch

I read several SO answers suggesting custom styles, but it is unclear how to request the background color of the parent element in this situation. As far as I can tell, they are all the same!

>>> ttk.Style().lookup("TFrame", "background")
'systemWindowBody'
>>> ttk.Style().lookup("Notebook", "background")
'systemWindowBody'
>>> ttk.Style().lookup("Notebook.client", "background")
'systemWindowBody'
>>> ttk.Style().lookup("Notebook.tab", "background")
'systemWindowBody'

Example code for the screenshot above :

import Tkinter
import ttk

class GUI(object):
    def __init__(self,root):
        self.root = root
        self.root.title(u"Frame Mismatch Example")
        self.mainframe = ttk.Frame(self.root, padding=(6, 6, 12, 12))
        self.mainframe.grid(sticky='nwse')

        self.notebook = ttk.Notebook(self.mainframe)
        self.tab1 = ttk.Frame(self.notebook)
        ttk.Button(self.tab1, text='Exit', command=self.root.destroy).pack(padx=100, pady=100)
        self.notebook.add(self.tab1, text="Tab 1")
        self.notebook.pack()

def main():
    root = Tkinter.Tk()
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)
    makeGUI = GUI(root)
    root.mainloop()

if __name__ == '__main__':
    main()

: Python 2.7.8, Tcl/Tk 8.5.15 ( Tk.eval('info patchlevel')).

+4
1

'systemWindowBody' sys.platform OSX.

, OSX. ( tkinter, : ttk.Notebook)

, , , , , .

+2

All Articles