我正在使用python 3 tkinter和sqlite
我在tkinter Text Widget
中有数据,然后需要拆分并将其保存在数据库表中,这是我的代码尝试
data = txtReceipt.get("4.0" ,"end")
for line in data.splitlines()[2:-2]:
no = line.split()[2:3]
name = line.split()[1:2]
price = line.split()[3:4]
series = line.split()[:1]
print(no)
c.execute("INSERT INTO billed_items(item_name,billed_qty,price,item_bill_series) VALUES(?,?,?,?)",(name),(no),(price),(series))
conn.commit()
但是我收到此错误消息TypeError: function takes at most 2 arguments (5 given)
任何帮助请
当我尝试读回文本小部件时,也在这里
su=c.execute("SELECT * FROM billed_items")
for row in su:
text = str(row)
txtReceipt.insert("end",str(row[0])+" "+str(row[1])+'\t\t'+str(row[2])+'\t'+" "+str(row[3])+"\n")
在那里,它只读取表的最后一行,我不知道为什么他不能读取所有行
答案 0 :(得分:2)
需要在元组中提供值。试试这个
query = ("INSERT INTO billed_items(item_name,billed_qty,price,item_bill_series) VALUES(?,?,?,?)")
c.execute(query,((name),(no),(price),(series))
conn.commit()