-1

I'm creating object oriented tkinter application, but I can't find way to get values from entry.

class App(tk.Frame):
    from verification import Verification
    validation = Verification()

    def __init__(self, parent, *args, **kwargs):

        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent

        self.email = tk.Entry(self).grid(column=1, row=4)
        self.email_lb = tk.Label(self, text='Email: ', font='Helvetica 11').grid(column=0, row=4)

        self.submit = tk.Button(self, text="Check", width=30, command = self.check_validity).grid(column=1, row=11)

    def check_validity(self, *args):
        email = self.email.get()
        print(email)

But when running this code I get this error

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1895, in __call__
    return self.func(*args)
  File "C:\Users\kryst\PycharmProjects\covidForm\app.py", line 164, in check_validity
    email = self.email.get()
AttributeError: 'NoneType' object has no attribute 'get'

Does anyone know how to solve this?

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
krystof18
  • 231
  • 3
  • 14
  • 1
    change `self.email = tk.Entry(self).grid(column=1, row=4)` to `self.email = tk.Entry(self);self.email.grid(column=1, row=4)` – TheLizzard Feb 26 '21 at 11:29

1 Answers1

1

Ok this is a very common mistake. When you create your tk.Entry you do this:

self.email = tk.Entry(self).grid(column=1, row=4)

That creates the entry then immediately calls its .pack method. It stores whatever .pack returns (always None) to self.email. What you want to do is this:

self.email = tk.Entry(self)
self.email.grid(column=1, row=4)
TheLizzard
  • 7,248
  • 2
  • 11
  • 31