[Tkinter-discuss] New Full Tkinter document editor widget -- suggestions, comments, etc.
ron.longo at cox.net
Tue Mar 25 02:52:49 CET 2008
I've posted a demo (http://tkinter.unpy.net/wiki/StyledEditor). This demo
creates a widget with full "styled editing" capabilities; sort of a
mini-word processor. It runs "as is" on my WinXP machine with Python 2.5.
The demo allows styling of any selected text via toolbars; just select the
text, then select the styling. Also included are buttons to save and
retrieve all content and styling information (works for the small tests I've
tried myself, not guaranteed bug-free).
The actual widget wraps the Text widget to give greater freedom in the
assignment of any single styling attribute to any region. This differs from
the Text widget itself in that the Text widget does not allow you to
individually assign a family, size, weight or slant with tag_config(). That
is, for example, you can't simply apply 'bold' to some region of text.
This demo was written quite quickly (I pounded it out over the weekend) so
I'm sure it's full of bugs. Also in my desire to get something working
quickly its API doesn't really work like a normal widget, so I guess this
serves as more of a proof of concept than full-blown widget but the basic
functionality is there. I'm presenting it here because I thought maybe
others might have thoughts on how to improve it.
applyStyleAttribute( index1, index2, attributeName, attributeValue )
This method is is frontend to the business. attributeName and
attributeValue may be any option accpeted by tag_config() of the Text widget
along with appropriate value. There are also some ''new'' options:
- 'family', attributeValue is a font family name
- 'size', attributeValue is a font point size
- 'weight', attributeValue is one of: 'normal', 'bold'
- 'bold', attributeValue is a boolean (alternative to using 'weight')
- 'slant', attributeValue is one of: 'roman', 'italic'
- 'italic', attributeValue is boolean (alternative to using 'slant')
Several previously existing options have some new values:
'spacing1', 'spacing2' and 'spacing3' may take 'None', 'Half Line', 'One
Line' or 'Two Lines' in addition to any of the values acceptable by
'offset' may take 'normal', 'superscript' or 'subscript' in addition to any
value acceptable by tag_config.
Please download and try-out my demo
(http://tkinter.unpy.net/wiki/StyledEditor). I'm anxious for suggestions
More information about the Tkinter-discuss