Tkinter, retrieving value from an entry
Question: So I am making a simple GUI program in python using Tkinter. The problem is
that when I try to retrieve the value from my Entry using a button, it comes
back with an `error()`:

    
    
    print(ex1.get())
    AttributeError: 'NoneType' object has no attribute 'get'
    

Can someone please help me avoid this?

This is my code:

    
    
    root = Tk()
    
    root.minsize(300,300)
    root.maxsize(300,300)
    
    
    n = ttk.Notebook()
    
    f1 = Frame(n,height=280,width=280)
    f1.propagate(0)
    lx1 = Label(f1,text="x",width=5).grid(row = 1,column=0) 
    ex1 = Entry(f1,width = 10).grid(row = 1,column = 1)
    
    ly1 = Label(f1,text="y",width=5).grid(row=3,column=0)
    ey1 = Entry(f1,width = 10).grid(row=3,column = 1)
    
    def value():
        print(ex1.get())
    
    
    Bcreate = Button(f1,text="CREATE",command=value).grid(row = 10,column =  5)
    n.add(f1,text="add point")
    
    f2 = Frame(n)
    n.add(f2,text="draw line")
    
    
    n.pack()
    

Thank you for your help.


Answer: Please read how to post a proper [MCVE](https://stackoverflow.com/help/mcve)

Here is one for your problem:

    
    
    from tkinter import Tk, Entry
    
    root = Tk()
    ent = Entry(root).pack()
    print(ent)
    print(ent.get())
    

This prints

    
    
    None
    Traceback (most recent call last):
      File "F:\Python\mypy\tem.py", line 6, in <module>
        print(ent.get())
    AttributeError: 'NoneType' object has no attribute 'get'
    

At this point, it should be obvious that `.pack()` returns `None`. So instead
bind the widget returned by Entry.

    
    
    from tkinter import Tk, Entry
    
    root = Tk()
    ent = Entry(root)
    ent.pack()
    print(ent)
    print(ent.get())
    

to get

    
    
    .2425099144832
    got  .
    

