简体   繁体   中英

Entry.get() Error in Python Tkinter

I'm trying to delete a record when the ID is inserted or the Name of the Recipe is entered by the user into the entry boxes. However it will not let me obtain the information from the entry box due to the following error:

"Traceback (most recent call last):
   File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
   return self.func(*args)
  File "H:\A-Level Computing\PROJECT!\Final Code.py", line 368, in delete_recipe
  Retrieve1 = EntryBox1.get()
 AttributeError: 'NoneType' object has no attribute 'get'"

The code is as follows:

def delete_recipe():

    global EntryBox1, EntryBox2, new_db

    Retrieve1 = EntryBox1.get()
    Retrieve2 = EntryBox2.get()

    new_db = sqlite3.connect('H:\A-Level Computing\PROJECT!\Recipes.db')

    new_db.execute("DELETE from RecipesDetails WHERE Retrieve1 = Rec_ID and Retrieve2 = Name")

    new_db.commit()
    new_db.close()

I would be really grateful for any help;. Thanks!

Make sure you don't have a line like the following:

entry = Entry().pack() # entry is None

pack , grid , place does return None . entry become None .

You should separate the Entry creatation and call to pack / grid / place method:

entry = Entry()
entry.pack()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM