Cursor Index From Tkinter.Text in <KeyRelease> Gives Insconsistent Column, Test Case

[email protected]
Newsgroups gmane.comp.python.tkinter
Message-ID <[email protected]>


I want to get the cursor position (line and column) of the insertion point of a Tkinter.Text, but you may assume the answer is easy until you run this simple test run.  Acutally I hope someone finds it easy.

PROBLEM: My text editor project requires a custom undo/redo for Tkinter.Text. I put in the same string for both Test One and Test Two below, but undo does not act consistently due to a inconsistent column variable in KeyRelease event handler given by Tkinter. The problem seems to be that I type too fast for second test which produces a bad column value. Can you help me find the problem?

TWO TEST PROCESS TO REPRODUCE THE ERROR:

TEST ONE

        Type this string slowly: 'one two three'
        Press F1 to see each word undo.

    Result: Works fine. (For me atleast. Ephasis: type slowly.)

TEST TWO

        Type the same string as fast as you can: 'one two three'
        Press F1 to see each word undo.

    Result: Gets the wrong column and does not undo properly. (Restart script and repeat this step if you don't see the error at first, it sometimes works fine with fast typing. I usually get it with 3 to 4 tries at the most.)

QUESTION: Is this a bug in Tkinter, or am I not understanding something specific within Tkinter that would produce consistent columns for my undo/redo records?



from Tkinter import *

class TextView(Text):

    def __init__(self, root):
        Text.__init__(self, root)

        self.history = History(self)
        self.bind("<KeyRelease>", self.keyRelease)

        # used to capture a char at a time in keyRelease.  If space char is pressed it , self.word)

if __name__ == "__main__":
    root = Tk()
    root.geometry("400x200+0+0")

    textView = TextView(root)
    textView.pack()
    root.bind("<F1>", textView.undo)
    root.bind("<F2>", textView.redo)

    root.mainloop()


---
Alle Postfächer an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! Rundum glücklich mit freenetMail

_______________________________________________
Tkinter-discuss mailing list
[email protected]
https://mail.python.org/mailman/listinfo/tkinter-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.