-5
import tkinter
main_window=tkinter.Tk()
tkinter.Label(main_window,text='WTF is your name').grid(row=0,column=0)
tkinter.Label(main_window,text='Age').grid(row=1,column=0)
n=tkinter.Entry(main_window,width=50,borderwidth=5).grid(row=0,column=3)
a=tkinter.Entry(main_window,width=50,borderwidth=5).grid(row=1,column=3)
def on_click():
     print(f'Your name is {n},and your age is {a}')
tkinter.Button(main_window,text='Enter',command=on_click).grid(row=2,column=3)
main_window.mainloop()

The output is keep on printing None instead of my name and age

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • 1
    Welcome to Stack Overflow. Please read [ask] and **ask a question**. Start by giving a clear explanation of exactly the steps you take to provide input to the program (did you click somewhere? Do you type something?), exactly what you expect to see (what text should appear, and where?) and exactly what you do see (what text appears, and where?), and then explain the steps you already took to try to solve the problem yourself (did you read any error messages that appear? Did you understand them?) and ask a question (it should start with a word like "why" or "how", and end with a question mark). – Karl Knechtel Aug 19 '21 at 14:33
  • You have to `.get()` the text from the `Entry` widget. – 0x5453 Aug 19 '21 at 14:35
  • 2
    @0x5453 the Problem here is very common in python tkinter. You have to seperate your constructor, which returns the wdigets id, from the geometry method, which returns None. In addition you have right and there needs to be a call to the entrys get method. [Classic answer to this](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) – Thingamabobs Aug 19 '21 at 14:38
  • @Atlas435 Just a minor detail: the constructor returns the widget not the widget's id. If you use `.create_****` is the only time you will get an id in `tkinter`. – TheLizzard Aug 19 '21 at 15:12
  • @TheLizzard its more or less the *id* of a tcl point of view. [Reference](https://docs.python.org/3/library/tkinter.html#a-very-quick-look-at-tcl-tk) – Thingamabobs Aug 19 '21 at 15:21
  • @Atlas435 I would say that the widget's id (which you aren't supposed to use) is: `._w`. It's a string like `".!label"`. Also from what I know it's a variable in `tcl`'s world. – TheLizzard Aug 19 '21 at 15:31

1 Answers1

2

Because you have to get the string from the entry field. Here's an example:

entry = tk.Entry(root)
entry.pack()
def verify():
    print(int(entry.get()))  

Entries aren't strings, they're more like some sort of weird input that it's a different format from Python. This, you have to convert it