簡體   English   中英

Python Tkinter中的Entry.get()錯誤

[英]Entry.get() Error in Python Tkinter

我試圖在插入ID或用戶在輸入框中輸入食譜名稱時刪除記錄。 但是由於以下錯誤,它不會讓我從輸入框中獲取信息:

"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'"

代碼如下:

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()

我將非常感謝您的幫助; 謝謝!

確保您沒有類似以下內容的行:

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

packgridplace不會返回None entry變為None

您應該分開Entry並調用pack / grid / place方法:

entry = Entry()
entry.pack()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM