0

I am trying to get a text input from user and save it in a variable called newLine. When I print newLine i get 'None' I am unable to save the input from the user to a variable, please help, what am I doing wrong?

top = Tk()
L1 = Label(top, text="Enter new line").pack()
E1 = Entry(top).pack()
Button(top, text="OK", command=top.quit).pack()
top.mainloop()

newLine = str(E1)
print(newLine)
R.Coss
  • 1
  • 1
  • 1
  • 1
  • 1
    Possible duplicate of [Why is Tkinter Entry's get function returning nothing?](http://stackoverflow.com/questions/10727131/why-is-tkinter-entrys-get-function-returning-nothing) – Stijn Van Daele Dec 29 '16 at 21:02
  • code `E1 = Entry(top).pack()` assign to `E1` value returned by `pack()` which always returns `None`. You have to to it in two steps `E1 = Entry(top)` and `E1.pack()` . BTW: `L1` also has `None` but you don't use it so you can write it without `L1 =`. – furas Dec 29 '16 at 23:58
  • BTW: if you will have correct `E1` then you have to use `value = E1.get()` and `E1.insert(... , new_value)` - not `value = str(E1)` and `E1 = new_value` – furas Dec 30 '16 at 00:01

1 Answers1

0

Have a look at the .get function.

Moreover, have a look at the following links:

Why is Tkinter Entry's get function returning nothing?

How to get text from Entry widget

They will help you out.

Community
  • 1
  • 1
Stijn Van Daele
  • 285
  • 1
  • 14