'Clear the already existing content on button clicking

In tkinter, I'm using a button click to open a file and extract its name. Once the file is reopened it opens a file again and should prints the name of the file again. But when this is done, the earlier content doesn't clear out and appears like below.

enter image description here

On each button click the below function gets call.

def display_csv_file(self,parent):
    try:
        
        self.file_name = filedialog.askopenfilename(initialdir = '/Desktop',
                                                    title = 'Select csv file',
                                                    filetypes = (('csv file','*.csv'),
                                                                 ('csv file','*.csv')))
        
        list2=self.file_name.split('/')
        
        
        df = pd.read_csv(self.file_name)
          
        if (len(df)== 0):
            msg.showinfo('No records', 'No records')
            
        # Now display the DF in 'Table' object
        # under'pandastable' module
        
        
        self.f2 = tk.LabelFrame(parent)      
        
        tk.Label(parent,text = 'File Name :- {}'.format(list2[-1]),
                      font = ('Arial', 12, 'bold'),
                      fg = '#000000').place(relx=0.1,rely=0.24)
        
        self.f2.place(height = 420, width=650, relx=0.1,rely=0.3)
        self.table = Table(self.f2, dataframe=df,read_only=False, showtoolbar=True, showstatusbar=True)
        options = {'colheadercolor':'green','floatprecision': 5}
        config.apply_options(options, self.table)

        self.table.show()
      
    except FileNotFoundError as e:
        print(e)
        msg.showerror('Error in opening file',e)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source