Tkinter entry-bind get method delayed [duplicate]

This question already has an answer here:

  • How to bind self events in Tkinter Text widget after it will binded by Text widget? 1 answer

I had this problem once and here is how I fixed it. You don't need to pass the the entry to the function. Since it is triggered by a keyboard key the function will take one argument. I made the argument of the function None by default to make it work when it is called by the button function.

from Tkinter import *

root = Tk()
E = Entry(root)
E.pack()
def printe(event=None):
    print E.get()
b = Button(root,text='ok',command = lambda: printe())
b.pack()
E.bind('<Key>',lambda x:printe())
root.mainloop()