Tkinter Python 3.7 AttributeError:“按钮"对象没有属性“获取" [英] Tkinter python 3.7 AttributeError: 'Button' object has no attribute 'get'
问题描述
我正在编写一个库存数据库程序.我是新手,所以我确定我做错了什么.
I'm writing an inventory database program. I'm a novice so I'm sure I have something wrong.
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(),但是我很确定自己已正确添加了输入字段.
I did not initially have a function, but realized that I would need one for the command in the button. The error points to my variable a = id_select.get(), but I'm pretty sure that I have my entry fields added properly.
推荐答案
您的错误是因为id_select是一个按钮.你最初有具有.get()的 id_select = Entry(编辑器,宽度= 30)
,但是您在 id_select = Button(editor,text ="Select Item)中替换了
(其中没有一个).您应该将按钮命名为其他名称. id_select
,command = select_item)
Your error is from the fact that id_select is a button. You initially had
id_select = Entry(editor, width=30)
which has .get(), but you replaced id_select
in id_select = Button(editor, text="Select Item", command=select_item)
which does not have one. You should name your button something else.
这篇关于Tkinter Python 3.7 AttributeError:“按钮"对象没有属性“获取"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!