Contents
Set Tkinter Window Background Color
The default background color of a GUI with Tkinter is grey. You can change that to any color based on your application’s requirement.
In this tutorial, we will learn how to change the background color of Tkinter window.
There are two ways through which you can change the background color of window in Tkinter. They are:
- using configure(bg='') method of tkinter.Tk class. or
- directly set the property bg of tkinter.Tk.
In both of the above said cases, set bg property with a valid color value. You can either provide a valid color name or a 6-digit hex value with # preceding the value, as a string.
Examples
1. Change background color using configure method
In this example, we will change the Tkinter window’s background color to blue.
Python Program
from tkinter import *
gui = Tk(className='Python Examples - Window Color')
# Set window size
gui.geometry("400x200")
# Set window color
gui.configure(bg='blue')
gui.mainloop()
CopyOutput

2. Change background color using bg property
In this example, we will change the Tkinter window’s background color to blue.
Python Program
from tkinter import *
gui = Tk(className='Python Examples - Window Color')
# Set window size
gui.geometry("400x200")
# Set window color
gui['bg']='green'
gui.mainloop()
CopyOutput

3. Using background for bg
You can use the property name bg as in the above two examples, or also use the full form background. In this example, we will use the full form background to set the background color of Tkinter window.
Python Program
from tkinter import *
gui = Tk(className='Python Examples - Window Color')
# Set window size
gui.geometry("400x200")
# Set window color
gui['background']='yellow'
# Gui.configure(background='yellow')
gui.mainloop()
CopyOutput

4. Using HEX code for background color
As already mentioned during the start, you can provide a HEX equivalent value for a color. In this example, we provide a HEX value to color and check the output.
Python Program
from tkinter import *
gui = Tk(className='Python Examples - Window Color')
# Set window size
gui.geometry("400x200")
# Set window color
gui['background']='#856ff8'
gui.mainloop()
CopyOutput

Summary
In this tutorial of Python Examples, we learned how to change the background color of Tkinter GUI window, with the help of well detailed Python example programs.