Tkinter Text Widget Background Color

Sathish S sathish at solitontech.com
Tue Feb 22 12:22:17 EST 2011


Jeff,

Thanks a lot. It worked great for me as well.

Thanks,
Sathish


On Tue, Feb 22, 2011 at 10:28 PM, Jeff Hobbs <jeff.hobbs at gmail.com> wrote:

> On Feb 22, 8:48 am, Terry Reedy <tjre... at udel.edu> wrote:
> > On 2/22/2011 6:50 AM, Peter Otten wrote:
> >
> > > 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()
> >
> > This example is helpful to me. I am curious though why the tk window
> > takes up the full screen instead of being much smaller as usual for
> > other examples I run. Shortening or shrinking the text has no effect.
>
> Because a 70point Helvetica font was requested, and the text widget
> has a default size of 80x24.  That would occupy the full size of most
> screens.
>
> Jeff
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110222/43650438/attachment-0001.html>


More information about the Python-list mailing list