I am trying to get the Text out of an Entry widget in Tkinter. It works with Entry1.get(), but it does not work using textvariable
What am I doing wrong ?
from Tkinter import *
master = Tk()
v = StringVar()def Entered(p1):print 'Got: ', Entry1.get()print 'Got: ', v.get()Entry1 = Entry(master, text = '', width = 25, textvariable = v)
Entry1.pack()
Entry1.bind('<Return>', Entered)
The problem is with text
.
If you give the text
argument, it seems that the textvariable.get()
will return nothing. I don't know if its a bug or not.
from Tkinter import *
master = Tk()
v = StringVar()def Entered(p1):print 'Got: ', Entry1.get()print 'Got: ', v.get()Entry1 = Entry(master, width = 25, textvariable = v) # No text now
Entry1.pack()
Entry1.bind('<Return>', Entered)
master.mainloop()
If you enter asd
it returns:
Got: asd
Got: asd
The interesting part that if you change the entry to:
Entry1 = Entry(master, text = 'sajt', width = 25, textvariable = v)
It will still return nothing with v.get()
not sajt
as i would expect.