-2
from tkinter import *
root = Tk()
root.geometry("850x900")
def pri():
    user = e.get()
    print(user)
e = Entry(root).pack()
b = Button(root, text = "Submit", command=pri).pack()
root.mainloop()

When I run this code, I get the following error:

"AttributeError: 'NoneType' object has no attribute 'get'"

David Duran
  • 1,786
  • 1
  • 25
  • 36
Sioul
  • 1
  • 1
    https://stackoverflow.com/questions/63079633/tkinter-grid-forget-is-clearing-the-frame/63079747#63079747 – Thingamabobs Sep 13 '20 at 11:53
  • You define the function ``pri`` before you define your entry ``e``. You have to define the function last. "NoneType" means that the object ``e`` hasn't been defined yet. – Leo Qi Sep 13 '20 at 12:04

1 Answers1

0

The problem is that you are trying to assign, to a variable, the result of a function that does not return anything (pack). You could first assign the Entry widget to the variable e and then pack. The following code works:

from tkinter import *

root = Tk()
root.geometry("850x900")
def pri():
    user = e.get()
    print(user)
e=Entry(root)
e.pack()
Button(root, text = "Submit", command=pri).pack()
root.mainloop()
David Duran
  • 1,786
  • 1
  • 25
  • 36
  • @Sioul - If this answer solved your problem then you need to accept it (ie click the big grey check-mark to the left of the answer). – OneMadGypsy Sep 13 '20 at 13:28