Treeview duplicates the value in tkinter treeview

Karthi

screenshot

When I click the refresh button it queries the data from SQL database, but in the list box it duplicate the values

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()

I tried to include the clear and delete function, but it is not working, can some one please help me

Warm Regards Janarthanan

acw1668

You need to clear listBox before populating data from database:

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))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive