Tkinter - Text - bullets

eb303 eric.brunel at pragmadev.com
Mon Sep 21 03:47:55 EDT 2009


On Sep 19, 5:53 pm, Thomas Lehmann <Iris-und-Thomas-Lehm... at T-
Online.de> wrote:
> > Something like this maybe?
> > ----
> > from Tkinter import *
>
> > root = Tk()
> > txt = Text(root, wrap='word')
> > txt.pack()
>
> > txt.tag_configure('text_body', font=('Times', 18), lmargin1=0,
> > lmargin2=0)
> > txt.tag_configure('bulleted_list', font=('Times', 18), lmargin1='10m',
> > lmargin2='15m', tabs=['15m'])
>
> > txt.insert(END, u"This is a normal paragraph. Let's make it a bit long
> > to see that it wraps as expected.\n", 'text_body')
> > txt.insert(END, u"\u00B7\tThis is the first item in the list.\n",
> > 'bulleted_list')
> > txt.insert(END, u"\u00B7\tThis is the second item in the list. Let's
> > make this one quite long too to see how it wraps.\n", 'bulleted_list')
>
> Thank you very much!
> However, the result is not that pretty as I have expected. The bullets
> are really small. When separating bullet and text then I can increase
> the font size for the bullet but then it does not fit to the text -
> vertical alignment is wrong. Also it's pretty unhandy to adjust the
> margins so that the text continues on next line starting at the same
> position as the first character from previous line.
>
> But it is a starting. I will check whether it is possible to place an
> image for a bullet. The size and position handling will be still there
> then -  I think so.

You can also use another font for bullets:
----
from Tkinter import *
import tkFont

root = Tk()

txt = Text(root, wrap='word')
txt.pack()

txt.tag_configure('text_body', font=('Times', 18), lmargin1=0,
lmargin2=0)
txt.tag_configure('bulleted_list', font=('Times', 18), lmargin1='10m',
lmargin2='15m', tabs=['15m'])
txt.tag_configure('bullets', font=('Dingbats', 18))

txt.insert(END, u"This is a normal paragraph. Let's make it a bit long
to see that it wraps as expected.\n", 'text_body')
txt.insert(END, u'\u25C6', 'bullets')
txt.insert(END, u"\tThis is the first item in the list.\n",
'bulleted_list')
txt.insert(END, u'\u25C6', 'bullets')
txt.insert(END, u"\tThis is the second item in the list. Let's make
this one quite long too to see how it wraps.\n", 'bulleted_list')

root.mainloop()
----

> Also note: The tab value from your example has not been accepted (s.th
> like. "invalid screen distance")

This is probably why you had all these alignment problems. But it's
weird, because the script I posted is copied and pasted from a really
script that I've run, and which doesn't cause any error. What is the
version of tcl/tk used by your Tkinter module? And what is your Python
version?



More information about the Python-list mailing list