20

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 :-)

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
T.Stimer
  • 255
  • 1
  • 2
  • 8

3 Answers3

14

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.

P S Solanki
  • 1,033
  • 2
  • 11
  • 26
4

You can use bg='#fff' or fg='f00' in tk.label.

Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
Tahil Bansal
  • 135
  • 6
0

note that background='' returns a label to its default color. I found this by printing the result of label.cget('background') where label is a tkinter label.

tevslin
  • 11
  • 2