Tkinter: Text.dump() method, and questions

A.M. Kuchling amk at 207-172-146-75.s75.tnt3.ann.va.dialup.rcn.com
Thu Apr 12 23:40:47 EDT 2001


On Wed, 11 Apr 2001 08:24:55 GMT, Fredrik Lundh <fredrik at pythonware.com> wrote:
>>     for i in range(len(t), 3):
>>         L.append( t[i:i+3] )
>
>better make that range(0, len(t), 3), right?

That'll teach me to edit code before posting it...  you're quite correct.

I've continued bonking away at my problem, and have gotten the (quite
possibly *really* misguided idea) that perhaps the more general task
is easier than the specialized one, so I'm taking a whack at an XML
editor widget that incrementally updates a DOM tree.  More questions:

* Given two indexes in a Text widget, like '4.16' and '5.14', how
  would you compute the # of characters between them?  
  (Chunks of character data are tagged as ranges, so when a keypress
  event comes in, it needs to figure out how far into the node it is.)

* From Grayson's book, I get the idea that you can return the string "break"
  from an event handler to prevent the event from being passed along
  to less specific bindings, but that doesn't seem to actually work in
  practice. 

    def init_widgets(self, master):
        self.text = Tkinter.Text()
        ... 
        self.text.tag_bind('readonly', '<KeyPress>',
                           func=self.ignore_key)

    def ignore_key(self, event):
        print 'key press ignored'
        return "break"

This is an attempt to make text tagged with the 'readonly' tag
unmodifiable.  What am I not understanding about Tk's event model?

--amk




More information about the Python-list mailing list