While working on a Tkinter + ttk based GUI on my Mac, I noticed a problem with background colors and the Notebook widget. When adding a ttk.Frame
as a ttk.Notebook
tab, the displayed background of the frame does not match the 'inset' background for the notebook tab.
How can I make the ttk.Frame
match the surrounding background color, without hard-coding a value that will look weird for non-Mac users?
I read a few SO answers suggesting custom styles, but it's unclear how to query for the parent widget's background color in this situation. As far as I can tell, they're 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 above screenshot:
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()
Important details: This is present with Python 2.7.8, Tcl/Tk 8.5.15 (as reported by Tk.eval('info patchlevel')
).