Tkinter python 3.7 AttributeError:'Button'对象没有属性'get'

问题描述 投票:0回答:1

我正在编写库存数据库程序。我是新手,所以我确定我做错了。

def select_item():
    #Create a Database or Connect to one
    conn = sqlite3.connect('inventory.db')
    #Create Cursor
    c = conn.cursor()

    a = id_select.get()

    c.execute("SELECT * FROM inventory WHERE oid = " + a)
    records = c.fetchall()

    for record in records:
        Item_editor.insert(0, record[0])
        Quantity_editor.insert(0, record[1])
        Asset_tag_editor.insert(0, record[2])
        Notes_editor.insert(0, record[3])

#Entry Fields
id_select = Entry(editor, width=30)
id_select.grid(row=0, column=1, pady=(20, 0))
Item_editor = Entry(editor, width=30)
Item_editor.grid(row=2, column=1)
Quantity_editor = Entry(editor, width=30)
Quantity_editor.grid(row=3, column=1)
Asset_tag_editor = Entry(editor, width=30)
Asset_tag_editor.grid(row=4, column=1)
Notes_editor = Entry(editor, width=30)
Notes_editor.grid(row=5, column=1)

#Button Time!
id_select = Button(editor, text="Select Item", command=select_item)
id_select.grid(row=1, column=0, columnspan=2, pady=10, padx=10, ipadx=100)

我最初没有功能,但是意识到我需要一个按钮来执行命令。该错误指向我的变量a = id_select.get(),但是我很确定我已经正确添加了输入字段。

sqlite tkinter python-3.7 attributeerror
1个回答
0
投票

您的错误是因为id_select是一个按钮。你最初有具有[.get]属性的id_select = Entry(editor, width=30),但是您替换了id_select中没有.get属性的id_select = Button(editor, text="Select Item", command=select_item)。您应该将按钮命名为其他名称。

© www.soinside.com 2019 - 2024. All rights reserved.