[Tkinter-discuss] Some random thought, looking for feedback

Kenneth McDonald kmmcdonald at wisc.edu
Wed Mar 17 01:54:47 EST 2004

Hi all. Thanks to all those who set up the list for the rest of us!

Here's a thought I had about Python/Tk in general. I've recently
been doing some funky stuff with the Text widget, and in order
to make my own life easier, I've come up with Python classes
that wrap marks and tags. The main reason to do this is that
once marks and tags are objects they are (IMHO) much easier
to use and extend. For example, I can say something like:

	mytag = instanceofmytextsubclass.tagat(index)

Now that it's an object, I can extend its behavior easily and
also can refer to it without referring to its containing widget.
For example, I might implement a function to see if a tag
touches a given index, and then just use it as

	if mytag.touches(index):

In fact, using those objects, I've been able to implements
a useful Range class, which can be used to cover a range
of text like a tag, but which does not disappear if the text
it encloses disappears, i.e. like a mark, and which can also
be identified uniquely (through its enclosed mark), or as
one of many ranges of the same "type" (through its enclosed
tag.) This was relatively easy using the wrapper classes, but
would have been, I believe, rather more difficult if done
with Tkinter alone.

I'm now starting to get into event handling and, as it turns out,
seem to be doing the same sort of thing with events, writing
wrapper classes. Since events apply throughout Tk and not
just in the Text widget, this got me wondering if it would be
worthwhile (and if there was any interest in) layering a more
Pythonic layer atop Tkinter. I could see this being useful in
a number of ways, not least in adding a certain amount of
"self-documentation" to the library (since python users would
be looking mostly at python code for reference, rather than
at code which more thinly wraps Tcl), and perhaps in permitting
non-Tkinter users to more easily use Tk. This is nothing against
Tkinter, it's a great package, I'm just wondering if it is worth the
effort to add a more object-oriented layer on top.

Comments most appreciated. Thanks,

More information about the Tkinter-discuss mailing list