Tkinter Button activebackground Option

Tkinter Button activebackground option sets the background color of button when the button is pressed and under the cursor.

In this tutorial, we will learn how to use activebackground option of Button() class with examples.

Different Types of Color Values

The value that has to be passed for this option is a string specifying the proportion of red, green, and blue in hexadecimal digits. You can also pass a standard color like red, green, black, white, etc.

Following are the different types of color values that you can provide to activebackground option.

#4 bits per color
tkinter.Button(window_main, activebackground='#rgb') #f00, #8af
#8 bits per color
tkinter.Button(window_main, activebackground='#rrggbb') #ff853a
#12 bits per color
tkinter.Button(window_main, activebackground='#rrrgggbbb') #ff8aba53a
#standard color names
tkinter.Button(window_main, activebackground='red') #red, green, yellow, blue
ADVERTISEMENT

Example 1 – Tkinter Button – Change Active Background Color

In the following program, we will change the active background color of Tkinter Button.

example.py – Python Program

import tkinter

window_main = tkinter.Tk(className='Tkinter - TutorialKart', )
window_main.geometry("400x200")

button_submit = tkinter.Button(window_main, text ="Submit", activebackground='#78d6ff')

button_submit.pack()
window_main.mainloop()

Output

When you run the application, you will see the following window.

Tkinter Button

During the click on button, you will see the active background color set.

Tkinter Button activebackground

Conclusion

In this Python Tutorial, we learned about Tkinter Button option “activebackground” with the help of example Python programs.