Tkinter Qs

Matthew Dixon Cowles matt at mondoinfo.com
Sat Jun 9 13:40:10 EDT 2001


On Sat, 09 Jun 2001 13:07:03 -0400, Adonis <deltapigz at telocity.com>
wrote:

>what form of measurement does Tkinter use? Pixels or DIB?

Sometimes it uses pixels, sometimes it uses lines, and sometimes
it uses characters.

b=Button(root,text="Test",width=10) # 10 characters wide
t=Text(root,width=20,height=2) # 20 characters wide, 2 lines high
f=Frame(root,width=25,height=35,bg="green") # 25 by 35 dots 

This is often maddening.

Fredrik Lundh mentions a way of working around this odd use of
multiple units of measure at (wrapped for line length):

http://www.pythonware.com/library/tkinter/
  introduction/x1309-patterns.htm

That's from his excellent An Introduction to Tkinter. I recommend
it highly.

>why doesnt this work? (text not being colored)
>t = Text(frame, width=50, height=15)
>t.pack()
>t.tag_config("test", foreground="red")
>t.insert(END, "test")

The first argument to tag_config() is a user-defined tag name. The tag
needs to be added to specific characters or character ranges:

t=Text(root, width=50, height=15)
t.pack()
t.tag_config("mytag", foreground="red")
t.insert(END, "test")
t.tag_add("mytag","1.0","1.4")

You can also specify the tag name when you're inserting text:

>>> t.insert(END,"wibble","mytag")

Regards,
Matt



More information about the Python-list mailing list