【发布时间】:2020-12-08 05:01:12
【问题描述】:
我正在尝试使用 TKinter 库构建库 GUI。我有一个 TreeView 显示数据库中的数据,但我希望自动生成 ID 列。创建表的代码被注释了,因为我已经运行过一次并且我确实创建了表。 The error I am getting is this.<<<<<<<<
def Add_New():
#Create Second Window
add_win=Toplevel()
add_win.geometry("500x310")
add_win.title("Add a new item")
#Create a database or connect to one
conn=sqlite3.connect('warehouse.db')
#Create cursor
c=conn.cursor()
#Create Table ONLY ONCE after that comment it.
#c.execute("""CREATE TABLE inventory(
# id_no integer primary key AUTOINCREMENT,
# customer_name text,
# part_no integer,
# tool_no text,
# descr_item_produced text,
# customer_prod_code text,
# location_item text,
# bar_code text,
# notes_comments text
# )""")
#Commit Changes
conn.commit()
#Create Submit Function for New Item
def submit():
conn=sqlite3.connect('warehouse.db')
#Create cursor
c=conn.cursor()
#Insert Into Table
c.execute("INSERT INTO inventory VALUES(:c_name,:p_no,:t_no,:d_item,:c_code,:l_item,:b_code,:n_comm)",
{
'c_name' : c_name.get(),
'p_no' : p_no.get(),
't_no':t_no.get(),
'd_item':d_item.get(),
'c_code':c_code.get(),
'l_item':l_item.get(),
'b_code':b_code.get(),
'n_comm':n_comm.get(),
})
#Commit Changes
conn.commit()
#Close Connection with db
conn.close()
【问题讨论】:
-
请提供minimal reproducible example。此外,除非绝对必要,否则请不要将信息作为图像共享。请参阅:meta.stackoverflow.com/questions/303812/…、idownvotedbecau.se/imageofcode、idownvotedbecau.se/imageofanexception。
标签: python sqlite tkinter treeview auto-increment