How to set default background colour tkinter How to set default background colour tkinter tkinter tkinter

How to set default background colour tkinter


If you want to get the default background at runtime, you can use the cget method. This may return a color name rather than an rgb value.

import Tkinter as tkroot = tk.Tk()bg = root.cget("background")# eg: 'systemWindowBody'

You can convert that to a tuple of the red, green and blue components

rgb = root.winfo_rgb(bg)# eg: (65535, 65535, 65535)

You can then format the value as a hex string if you wish:

color = "#%x%x%x" % rgb# eg: '#ffffffffffff'

To reset the background after changing it, save the value, and then use the value with the configure command:

original_background = root.cget("background")...root.configure(background=original_background)


Try this:

root.configure(background='SystemButtonFace')


Another option is just to clear the background setting.For example

import Tkinter as tkroot = tk.Tk()lbl_status = ttk.Label(root, width=20, text="Some Text")lbl_status['background'] = 'yellow'   # Set background to yellowlbl_status['background'] = ''         # Reset it to system default