Modifying Entry widget diabledforeground in Tkinter...

Peter Otten __peter__ at web.de
Thu Mar 4 15:25:39 EST 2004


Rod Stephenson wrote:

> 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



More information about the Python-list mailing list