Search code examples
pythontkintertkinter-entry

Why am I getting an error message saying: " RefNumCur = RefNumEntry.get() AttributeError: 'NoneType' object has no attribute 'get' "?


This code all occurs within a class of the main menu screen of my Vat Calculator Program. I am having trouble retrieving values from my entry boxes.

The first few lines initialises text variables to be used by the Entry boxes.

    RefNumCur = StringVar()
    AddressCur = StringVar()
    DateCompCur = StringVar()
    DateBankCur = StringVar()
    JobSourceCur = StringVar()
    JobTypeCur = StringVar()
    AmountCur = StringVar()

Here I make a function that starts a chain of validity algorithms before the values are saved to a database. But first I need to get the values from the entry boxes.

    def SaveEntry(*args):
        RefNumCur = RefNumEntry.get()
        AddressCur = AddressEntry.get()
        DateCompCur = DateCompEntry.get()
        DateBankCur = DateBankEntry.get()
        JobSourceCur = JobSourceEntry.get()
        JobTypeCur = JobTypeEntry.get()
        AmountCur = AmountEntry.get()

        CheckRefNum(RefNumCur)

Here is where I have made and placed the entry boxes.

    RefNumEntry = Entry(textvariable = RefNumCur).grid(row = 2,column =3, columnspan = 2)
    AddressEntry = Entry(textvariable = AddressCur).grid(row = 3,column = 3, columnspan = 2)
    DateCompEntry = Entry(textvariable = DateCompCur).grid(row = 4,column =3, columnspan = 2)
    DateBankEntry = Entry(textvariable = DateBankCur).grid(row = 5,column = 3, columnspan = 2)
    JobSourceEntry = Entry(textvariable = JobSourceCur).grid(row = 6, column =3, columnspan = 2)
    JobTypeEntry = Entry(textvariable = JobTypeCur).grid(row = 7, column =3, columnspan = 2)
    AmountEntry = Entry(textvariable = AmountCur).grid(row = 8,column = 3, columnspan = 2)

Solution

  • grid returns None. (same for pack, place)

    You need to separate lines like this:

    RefNumEntry = Entry(textvariable=RefNumCur).grid(row=2, column=3, columnspan=2)
    

    into:

    RefNumEntry = Entry(textvariable=RefNumCur)
    RefNumEntry.grid(row=2, column=3, columnspan=2)
    

    Otherwise, RefNumEntry will refer None instead of Entry object.