Tkinter Text widget reading input (how to do overwrite mode?)

J.Jacob joost_jacob at hotmail.com
Mon Apr 29 10:24:41 EDT 2002


Here is a question for somebody with experience with Tkinter Text widgets.
I have a Tkinter widget that inherits from Frame and it has a self.text
attribute of type Text.
To read user input in my widget (until the user presses RETURN) i add
the following two methods (this is part of my code):

    def readxy(self, x=0, y=1):
        where = `y`+'.'+`x`
        self.startUserInput = where
        self.userInput = StringVar()
        self.userInput.set('')
        self.text.mark_set(INSERT, where)
        self.text.bind('<Return>', lambda event, self=self: self._onEnter(event))
        self.text.focus()
        self.text.update()
        self.text.wait_variable(self.userInput)
        return self.userInput.get()
    def _onEnter(self, event):
        self.userInput.set(self.text.get(self.startUserInput, INSERT))
        self.text.mark_unset(INSERT)
        self.text.unbind('<Return>', '')

This works fine, but the user is typing in 'INSERT' mode.  That means that any
text on the line after the cursor is shifted right with each typed character.
My question is: how can i get an 'OVERWRITE' mode ?
Do i have to program that manually or is there a simple way to 'put a Text
widget in overwrite mode'.  Did somebody do this before?  Of course i searched
the net for an answer before asking it here on c.l.p.  I noticed that IDLE
does not have an 'OVERWRITE' mode either, nor does any other editor
implemented with Tkinter i could find on the net.

Joost Jacob
www.liacs.nl/home/jjacob/

I have a very small mind and must live with it.
                -- E. Dijkstra



More information about the Python-list mailing list