I'm trying to build my first GUI program and want to know who to change the label text color? for instance, changing it to 'red'
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="what's my favorite video?", pady=10, padx=10, font=10,)
label.pack()
click_here = tk.Button(root, text="click here to find out", padx = 10, pady = 5)
click_here.pack()
root.mainloop()
Thanks a lot :-)
We can also change the foreground color by using the 'fg' property of the button widget in Tkinter. We can also use the configure method to change the color. As we know that we can use the 'bg' and 'fg' property of the Button widget to change the color, we need to pass this variable while using the Button object.
This is the easiest one , Just define a Function and then a Tkinter Label & Button . Pressing the Button changes the text in the label.
You can use the optional arguments bg
and fg
(Note that you might need to use a different option like highlightbackground
on MacOS system as stated In this answer ) - which I believe is a known issue with tk.Button
on MacOS.
import tkinter as tk
root = tk.Tk()
# bg is to change background, fg is to change foreground (technically the text color)
label = tk.Label(root, text="what's my favorite video?",
bg='#fff', fg='#f00', pady=10, padx=10, font=10) # You can use use color names instead of color codes.
label.pack()
click_here = tk.Button(root, text="click here to find out",
bg='#000', fg='#ff0', padx = 10, pady = 5)
click_here.pack()
root.mainloop()
The only reason I added this as an answer is because the last answer I wrote on a similar question for someone on SO, didn't work just because they were using a Mac. If you are on a Windows machine, you are fine.
You can use bg='#fff'
or fg='f00'
in tk.label
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With