Your code does work, it's just that '#CCCCCC'
is a very similar color to that of default. So it's hard to tell the difference.
If you color the text instead of the background for example, with foreground
option, it makes the text 'invisible':
import tkinter as tk
root = tk.Tk()
btn = tk.Button(root, text="asd")
btn['fg'] = '#CCCCCC'
btn.pack()
root.mainloop()
Using this answer one can inspect RGB values of colors let's see what they yield:
import tkinter as tk
root = tk.Tk()
btn = tk.Button(root, text="asd")
default_rgb = btn.winfo_rgb(btn['bg'])
wanted_rgb = btn.winfo_rgb('#CCCCCC')
reference_rgb = btn.winfo_rgb('grey')
print(default_rgb)
print(wanted_rgb)
print(reference_rgb)
btn.pack()
root.mainloop()
As you can see the two colors, the default SystemButtonFace
and #CCCCCC
are very similar especially when you think of how close of a reference grey is and how far its rgb values are.
See below example for an easy to tell coloring:
import tkinter as tk
root = tk.Tk()
btn = tk.Button(root, text="Colors")
#when button isn't pressed
btn['fg'] = 'orange'
btn['bg'] = 'blue'
#when button is pressed
btn['activeforeground'] = 'red'
btn['activebackground'] = 'green'
btn.pack()
root.mainloop()