954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Events are always one Event behind

def doKey(e):
	print(e.widget.get("1.0","end"))
root= Tk()
root.title('yada')
txta = Text(root, width=40, height=10)
txta.bind("<Key>", doKey)
txta.pack(side=LEFT)
root.mainloop()


Pressing a key in this text area will always output the string prior to your pressing the key. Am I missing something?

pdxwebdev
Newbie Poster
8 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Ok, well, what I ended up doing was just concatenating event.char to the end of widget.get(). If anyone has a better idea, please fill me.

pdxwebdev
Newbie Poster
8 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

hi,
i think you almost got it, here's what I have:

from Tkinter import *
def doKey(e):
	print(e.widget.get( 1.0, END + '-1c' ) + e.char )
root= Tk()
root.title('yada')
txta = Text(root, width=40, height=10)
txta.bind("<Key>", doKey)
txta.pack(side=LEFT)
root.mainloop()


Btw, that kind of behaviour is just what I need for my project, sooo thanks a lot for that dude :) hope this helps :)

masterofpuppets
Posting Whiz in Training
272 posts since Jul 2009
Reputation Points: 20
Solved Threads: 74
 
def doKey(e):
	print(e.widget.get("1.0","end"))
root= Tk()
root.title('yada')
txta = Text(root, width=40, height=10)
txta.bind("<Key>", doKey)
txta.pack(side=LEFT)
root.mainloop()

Pressing a key in this text area will always output the string prior to your pressing the key. Am I missing something?

You could usetxta.bind("", doKey)

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Thank you everyone!

pdxwebdev
Newbie Poster
8 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: