Sathish S wrote:

> Hi Ppl,
> 
> I'm using the Tkinter Text Widget in my user interface. I'm trying to
> create a blinking effect for this Text Widget. I saw from the
> documentation I can set the color if the widget when I create it.
> 
> x=Text(root,bg='#CFF')
> 
> However, I couldn't find any property or function that set's the
> background color. Is there any way to set the back ground color after the
> object is created.
> 
> Thanks,
> Sathish

import Tkinter as tk
from itertools import cycle

root = tk.Tk()
text = tk.Text(root, font=("Helvetica", 70))
text.pack()

text.insert(tk.END, "Hello, geocities")
text.tag_add("initial", "1.0", "1.1")
text.tag_add("initial", "1.7", "1.8")

colors = cycle("red yellow blue".split())
initial_colors = cycle("#8f8 #f08".split())

def switch_color():
    # change the complete widget's background color
    text["bg"] = next(colors)

    # change the background color of tagged portions
    # of the widget's conten
    text.tag_config("initial", background=next(initial_colors))

    # do it again after 300 milliseconds
    root.after(300, switch_color)

# call the color-setting function manually the first time
switch_color()
root.mainloop()

Does this help?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to