
當我單擊重繪 按鈕時,它會從 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()
我試圖包含清除和洗掉功能,但它不起作用,請有人幫助我
熱烈的問候賈納塔南
uj5u.com熱心網友回復:
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))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/490118.html
