Modifying Entry widget diabledforeground in Tkinter...

R

Rod Stephenson

I want to modify an Entry widget to have the disabledforeground color
be black rather than grey (so that in certain circumstances the widget
acts as a label for displaying some stuff; the normal gray disabled
foreground color isnt really readable).

In Tk this is just a matter of using configure -disabledforeground
but this seems not to be an option with Tkinter. Reading through the
source there is a tk_setPallete which seems to do this globally, but
is there any way to do this locally for the widget?

tia
 
P

Peter Otten

Rod said:
I want to modify an Entry widget to have the disabledforeground color
be black rather than grey (so that in certain circumstances the widget
acts as a label for displaying some stuff; the normal gray disabled
foreground color isnt really readable).

In Tk this is just a matter of using configure -disabledforeground
but this seems not to be an option with Tkinter. Reading through the
source there is a tk_setPallete which seems to do this globally, but
is there any way to do this locally for the widget?

import Tkinter as tk
root = tk.Tk()
var = tk.StringVar()
var.set("one two three")
entry = tk.Entry(root, disabledforeground="blue", state="disabled",
textvariable=var)
entry.pack()

enabled = False
states = {False:"disabled", True:"normal"}
def toggle():
global enabled
button["text"] = states[enabled]
enabled = not enabled
entry["state"] = states[enabled]
button = tk.Button(root, text="normal", command=toggle)
button.pack()

root.mainloop()

I took the freedom to use blue for the sake of the example.

Peter
 
E

Eric Brunel

Rod said:
I want to modify an Entry widget to have the disabledforeground color
be black rather than grey (so that in certain circumstances the widget
acts as a label for displaying some stuff; the normal gray disabled
foreground color isnt really readable).

In Tk this is just a matter of using configure -disabledforeground
but this seems not to be an option with Tkinter.

I may be wrong, but AFAIK, the options you pass to the configure methods or used
when creating an object are just passed almost "as is" to the tcl layer by
Tkinter. So, except in very special cases, there can't be an option available in
tk that isn't in Tkinter... I surely never saw such an option.

So I just wonder what made you think the option wasn't available?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top