Tkinter Button fg
Tkinter Button fg option sets the foreground color of button. In other words, the color of the Button’s text.
In this tutorial, we will learn how to use Button’s fg option of Button() class with examples.
Color Values for Button Foreground
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 fg option.
#4 bits per color
tkinter.Button(window_main, fg='#rgb') #f00, #8af
#8 bits per color
tkinter.Button(window_main, fg='#rrggbb') #ff853a
#12 bits per color
tkinter.Button(window_main, fg='#rrrgggbbb') #ff8aba53a
#standard color names
tkinter.Button(window_main, fg='red') #red, green, yellow, blue
Example 1 – Tkinter Button Foreground Color or Text Color
In the following program, we will change the foreground 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", fg='#ff1944')
button_submit.config(width=20, height=2)
button_submit.pack()
window_main.mainloop()
Output
Conclusion
In this Python Tutorial, we learned about Tkinter Button fg option, to change foreground color of the Button, with the help of example Python programs.