我正在嘗試同時從樹視圖和資料庫 Mysql 中洗掉選定的記錄。將資料庫中的記錄插入到樹視圖中并從樹視圖中洗掉選定的記錄是有效的。
但我的問題是如何從資料庫中洗掉選定的記錄?
tv=ttk.Treeview(manage,columns=(1,2,3,4,5),show="headings",height="25")
tv.insert('','end',values=i)
uj5u.com熱心網友回復:
建議將iid選項設定ID為表中的:
for i in rows:
tv.insert('', 'end', iid=i[0], values=i) # assume ID is the first column in the table
然后你可以從里面的表中洗掉記錄,removeRecord()如下所示:
def removeRecord():
selected = tv.selection()
if selected:
# a row is selected
x = selected[0]
tv.delete(x)
# delete record from table
sql = 'DELETE FROM employeeInfo WHERE ID = %s'
mycursor.execute(sql, (x,))
# assume mydb is the connection object of MySQL database
mydb.commit() # make sure to commit the change
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/452618.html
