【问题标题】:Tkinter python 3.7 AttributeError: 'Button' object has no attribute 'get'Tkinter python 3.7 AttributeError:'Button'对象没有属性'get'
【发布时间】:2020-03-12 15:13:59
【问题描述】:

我正在编写一个库存数据库程序。我是新手,所以我确定我有问题。

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(),但我很确定我的输入字段已正确添加。

【问题讨论】:

  • emmm....id_select finally 是一个 button 小部件。您不应该使用相同的两个变量名称。
  • 我发现,当我检查我的代码是否有错误时,我完全错过了它。眼睛累了……

标签: sqlite tkinter python-3.7 attributeerror


【解决方案1】:

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

【讨论】:

  • 我完全错过了它。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-08
  • 2021-02-24
  • 2018-05-09
相关资源
最近更新 更多