[英]Treeview duplicates the value in tkinter treeview
當我單擊刷新按鈕時,它會從 SQL 數據庫中查詢數據,但在列表框中它會重復這些值
def show():
mysqldb = mysql.connector.connect(host="localhost", user="root", password="1986@", database="ecogreen")
mycursor = mysqldb.cursor()
mycursor.execute("SELECT id,Firstname,Lastname,Mobile,Location FROM customers1")
records = mycursor.fetchall()
for i, (id, Firstname, Lastname, Mobile, Location) in enumerate(records, start=2):
listBox.insert("", "end", values=(id, Firstname, Lastname, Mobile, Location))
mysqldb.close()
我試圖包含清除和刪除功能,但它不起作用,請有人幫助我
熱烈的問候賈納塔南
您需要在從數據庫中填充數據之前清除listBox
:
def show():
mysqldb = mysql.connector.connect(host="localhost", user="root", password="1986@", database="ecogreen")
mycursor = mysqldb.cursor()
mycursor.execute("SELECT id,Firstname,Lastname,Mobile,Location FROM customers1")
records = mycursor.fetchall()
mysqldb.close()
# clear table
listBox.delete(*listBox.get_children())
# populate table
for i, (id, Firstname, Lastname, Mobile, Location) in enumerate(records, start=2):
listBox.insert("", "end", values=(id, Firstname, Lastname, Mobile, Location))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.