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?

Recommended Answers

All 4 Replies

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.

Member Avatar for masterofpuppets

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 :)

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 use txta.bind("<KeyRelease>", doKey)

Thank you everyone!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.