Skip to content Skip to sidebar Skip to footer

Getting Data From Mysql Using Tkinter Button Gets Duplicated

I've a python script that uses tkinter and a button to get data from MySQL but every time I press the button the data gets duplicated like that: Code below: from tkinter import tt

Solution 1:

You can do a simple check, if there are items inside and then delete all the items, and if not insert, like:

defView():
    iflen(tree.get_children()): # If there are items inside 
        tree.delete(*tree.get_children()) # Delete all the itemselse:
        # Paste the rest of code

You can also define a flag and then check if data is inserted, and proceed accordingly, like:

inserted = False# Initially FalsedefView():
    if inserted:
        tree.delete(*tree.get_children())
        inserted = False# Set it to not inserted ifnot inserted: # Let this get triggered# Same codefor row in rows:
            print(row) 
            tree.insert("", tk.END, values=row)
        mydb.close()
        inserted = True# Set it to true.

Post a Comment for "Getting Data From Mysql Using Tkinter Button Gets Duplicated"