Question

I was trying to change the color of the words in my ttk.Entr widget when I set the state to disabled, I looked up the manual, there's an option called disabledforeground, so I wrote a test snippet as below: (BTW, I'm under Python 2.7)

from Tkinter import *
from ttk import *

root=Tk()

style=Style()
style.configure("TEntry",disabledforeground='red')

entry_var=StringVar()
entry=Entry(root,textvariable=entry_var,state='disabled')
entry.pack()

entry_var.set('test')

mainloop()

But the result shows no change in the color of "test", any idea what's wrong?

Was it helpful?

Solution 2

Try using Style.map instead of configure.

from Tkinter import *
from ttk import *

root=Tk()

style=Style()
style.map("TEntry",
          foreground=[("active", "black"), ("disabled", "red")]
          )

entry_var=StringVar()
entry=Entry(root,textvariable=entry_var,state='disabled')
entry.pack()

entry_var.set('test')

mainloop()

OTHER TIPS

I think that disabledforeground is an option for tk widgets but not for ttk widgets. On this page

http://wiki.tcl.tk/38127

you will see things like this in parts of the code that apply to tk widgets:

{-disabledforeground disabledForeground}

Here -disabledforeground refers to a configuration option and disabledforeground (without the leading minus sign) refers to a color that is defined near the bottom of the page:

set colors(disabledForeground) {#a3a3a3} ; # -disabledfg

You will see things like this in parts of the code that apply to ttk widgets:

{map -foreground disabled disabledForeground}

Here -foreground is the configuration option, and disabled is a state that the widget can be in. Again, disabledforeground is the actual color to be used when the widget is in that state.

I'm not a Tcl programmer, so I'm extrapolating here from tkinter and ttk, but this is the only reasonable interpretation of this code that I can come up with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top