osama syr
osama syr

Reputation: 27

How to change foreground color of a ttk button that is disabled?

When I disable a button the color change automatically to black. This is the code :

from tkinter import *
from tkinter import ttk
root=Tk()

style=ttk.Style()
style.configure('TButton', foreground='red')
bu1=ttk.Button(root, text="Hello world")
bu1.grid(row=0, column=0)

bu2=ttk.Button(root, text="Hello world2")
bu2.grid(row=1, column=0)

bu1.state(['disabled'])
bu2.state(['disabled'])

root.mainloop()

Any help?

Upvotes: 0

Views: 1830

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386382

Since you are using a ttk button, you can map certain attributes to different button states with the map method of the style object.

For example, to change the colors when the button state is "disabled", you can set the color like this:

style.map(
        "TButton",
        foreground=[("disabled", "black")]
)

For more information see 50.2. ttk style maps: dynamic appearance changes on the New Mexico Tech tkinter documentation, and also Styles and Themes on tkdocs.com

Upvotes: 1

Related Questions