John
John

Reputation: 341

Clear a Text Box within tkinter

I am trying to refresh a label in a tkinter GUI and its proving very difficult. I have tried the destroy() command and delete command e.g

def Erase():
    self.e1.delete(first=0,last=100)

I have read many posts and tkinter documentation but had no success

def retrieve_inputBoxes():
    VPNID = int(self.e1.get())
    df = pd.read_csv("Data.csv")
    output = (df[["field1", "field2", "field9"]][df["field4"]== VPNID])
    my_list1 = output["field1"].tolist()
    self.e1 = self.canvas.create_text(100 ,450 ,anchor='center', text=my_list1, font =('Helvetica', 8, 'bold'))

The data goes into the label just fine but the next time the data goes in, it overwrites the previous entry. Any help would be appreciated

Upvotes: 0

Views: 293

Answers (1)

strava
strava

Reputation: 765

The delete method needs to be called on the canvas object, not the variable self.e1. The create_text method returns an identifier, so this line:

self.e1 = self.canvas.create_text(... )

assigns that identifier to self.e1. You can use that variable to tell the delete method what to delete.

self.canvas.delete(self.e1)

Upvotes: 1

Related Questions