Tkinter Button activeforeground

Tkinter Button activeforeground option sets the foreground color (text color) of the button when the button got pressed and is under the cursor.

In this tutorial, we will learn how to use activeforeground 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 activeforeground option.

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

Example 1 – Tkinter Button Text Color when Pressed

In the following program, we will set a value for active foreground color (color of text in Button) for Tkinter Button.

example.py – Python Program

</>
Copy
import tkinter

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

button_submit = tkinter.Button(window_main, text ="Submit", activeforeground='#ff0000')

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 foreground color set.

Tkinter Button activeforeground

Conclusion

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