将变量插入sqlite数据库tkinter python

时间:2016-05-24 23:38:48

标签: python variables tkinter sqlite sql-insert

我正在尝试在单击按钮时插入变量中的数据(注意:插入部分正在使用硬代码,它是不可用的变量部分),在python 2.7.11 tkinter中插入sqlite3数据库。 这是我的代码:

    digit = 1
    color_label = 'blue'
def test():

    connection = connect(database = "shoes.db")

    best_shoes = connection.cursor()
  

sql =“INSERT INTO Shoes(Rank,Color)VALUES(?,?)”,           (digit,color_label); REPLACED

    best_shoes.execute("INSERT INTO Top_Ten(Rank, Color)VALUES(?, ?)",                
    (digit, color_label))

    best_shoes.execute(sql)

    rows_inserted = best_shoes.rowcount

    connection.commit()

    best_shoes.close()
    connection.close()


    return rows_inserted

save = Button(window, text = 'Save', command=test)
save.pack()
window.mainloop()

编辑:顺便说一句,我遇到了这个错误: InterfaceError:绑定参数0时出错 - 可能是不支持的类型。

0 个答案:

没有答案