Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter - Text - bullets

Reply
Thread Tools

Tkinter - Text - bullets

 
 
Thomas Lehmann
Guest
Posts: n/a
 
      09-18-2009
My intention is to write a small custom widget displaying text where
the text can have a simple wiki syntax. The main interest is to
support heading, bold, italic, underline, itemization and enumeration.

How can I implement itemization using the Tkinter.Text widget?
(bullets)
 
Reply With Quote
 
 
 
 
eb303
Guest
Posts: n/a
 
      09-18-2009
On Sep 18, 11:57 am, Thomas Lehmann <Iris-und-Thomas-Lehm...@T-
Online.de> wrote:
> My intention is to write a small custom widget displaying text where
> the text can have a simple wiki syntax. The main interest is to
> support heading, bold, italic, underline, itemization and enumeration.
>
> How can I implement itemization using the Tkinter.Text widget?
> (bullets)


Something like this maybe?
----
from Tkinter import *

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

txt.tag_configure('text_body', font=('Times', 1, lmargin1=0,
lmargin2=0)
txt.tag_configure('bulleted_list', font=('Times', 1, 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')

root.mainloop()
----

HTH
 
Reply With Quote
 
 
 
 
Thomas Lehmann
Guest
Posts: n/a
 
      09-19-2009
> Something like this maybe?
> ----
> from Tkinter import *
>
> root = Tk()
> txt = Text(root, wrap='word')
> txt.pack()
>
> txt.tag_configure('text_body', font=('Times', 1, lmargin1=0,
> lmargin2=0)
> txt.tag_configure('bulleted_list', font=('Times', 1, 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.

Also note: The tab value from your example has not been accepted (s.th
like. "invalid screen distance")
 
Reply With Quote
 
eb303
Guest
Posts: n/a
 
      09-21-2009
On Sep 19, 5:53 pm, Thomas Lehmann <Iris-und-Thomas-Lehm...@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', 1, lmargin1=0,
> > lmargin2=0)
> > txt.tag_configure('bulleted_list', font=('Times', 1, 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', 1, lmargin1=0,
lmargin2=0)
txt.tag_configure('bulleted_list', font=('Times', 1, lmargin1='10m',
lmargin2='15m', tabs=['15m'])
txt.tag_configure('bullets', font=('Dingbats', 1)

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?
 
Reply With Quote
 
Thomas Lehmann
Guest
Posts: n/a
 
      09-22-2009
> 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?


Using python 2.5 (with Tcl/Tk 8.4):

Traceback (most recent call last):
File "Text1.py", line 10, in <module>
txt.tag_configure('bulleted_list', font=('Times', 1,
lmargin1='10m', lmargin2='15m', tabs=['15m'])
File "E:\Python25\lib\lib-tk\Tkinter.py", line 3066, in
tag_configure
return self._configure(('tag', 'configure', tagName), cnf, kw)
File "E:\Python25\lib\lib-tk\Tkinter.py", line 1188, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: bad screen distance "['15m']"
 
Reply With Quote
 
eb303
Guest
Posts: n/a
 
      09-22-2009
On Sep 22, 7:45 am, Thomas Lehmann <Iris-und-Thomas-Lehm...@T-
Online.de> wrote:
> > 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?

>
> Using python 2.5 (with Tcl/Tk 8.4):
>
> Traceback (most recent call last):
> File "Text1.py", line 10, in <module>
> txt.tag_configure('bulleted_list', font=('Times', 1,
> lmargin1='10m', lmargin2='15m', tabs=['15m'])
> File "E:\Python25\lib\lib-tk\Tkinter.py", line 3066, in
> tag_configure
> return self._configure(('tag', 'configure', tagName), cnf, kw)
> File "E:\Python25\lib\lib-tk\Tkinter.py", line 1188, in _configure
> self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
> _tkinter.TclError: bad screen distance "['15m']"


Try tabs='15m' instead. Seems the list is not handled properly.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text formatting (bullets) issue with IE7 + knowledgenotebook Javascript 0 05-27-2011 09:23 PM
List item bullets Paul Lautman HTML 15 12-31-2006 12:42 AM
Bullets overlapping image aligned to left ComputerSnack HTML 7 04-13-2006 01:57 AM
Bullets not rendering properly babz XML 0 06-27-2005 06:57 AM
Datagrid and bullets Bob H ASP .Net 1 02-05-2004 01:26 PM



Advertisments