AttributeError: PageOne instance has no attribute 'delete'

Viewed 54

I am trying to validate the CSV input file, to ensure that the user is inputting the correct CSV file. However, I kept receiving the error AttributeError: PageOne instance has no attribute 'delete'. I can't seem to figure it out why.

Currently, when I input the correct/incorrect CSV file, popup will appear to tell me whether if I have input the correct file or not, but the code will not continue to file_entry.delete(0, tk.END) and the error AttributeError: PageOne instance has no attribute 'delete' appear.

Below are my codes for my Tkinter frame and the validation function.

class PageOne(tk.Frame):

    def get_procurement_file(file_entry):
        file_name = fd.askopenfilename(title="Select file", filetypes=(("CSV Files", "*.csv"),))
        entry_file = file_name.split("/")[-1]
        if entry_file == "government-procurement-via-gebiz.csv":
            file_entry.popup_successinfo()
            file_entry.delete(0, tk.END)
            file_entry.insert(0, entry_file)
        else:
            file_entry.popup_errorinfo()
            file_entry.delete(0, tk.END)
        # file_entry.delete(0,END)
        # file_entry.insert(0,file_name)

    def get_contractor_file(file_entry):
        file_name = fd.askopenfilename(title="Select file", filetypes=(("CSV Files", "*.csv"),))
        entry_file = file_name.split("/")[-1]
        if entry_file == "listing-of-registered-contractors.csv":
            file_entry.popup_successinfo()
            file_entry.delete(0, tk.END)
            file_entry.insert(0, entry_file)
        else:
            file_entry.popup_errorinfo()
            file_entry.delete(0, tk.END)
        # file_entry.delete(0,END)
        # file_entry.insert(0,file_name)

    def popup_successinfo(self):
        showinfo("Window", "Successfully input!")

    def popup_errorinfo(self):
        showinfo("Window", "Wrong input! Please insert the Correct File!")

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.entry_csv = tk.Entry(self, text="", width=80, font=20)
        self.entry_csv.place(x=250, y=380)
        self.entry_csv2 = tk.Entry(self, text="", width=80, font=20)
        self.entry_csv2.place(x=250, y=500)

        self.label = tk.Label(self, bg="#64dd17", height=10, font=30, text="1002 Dataset Analyzer")
        self.label.pack(fill="x")

        self.label = tk.Label(self, text="1st Dataset File: ", font=30)
        self.label.place(x=100, y=380)

        self.button = tk.Button(self, text="Browse...", width=10, height=2, command=lambda: self.get_procurement_file())
        self.button.place(x=1000, y=370)

        self.label = tk.Label(self, text="2nd Dataset File:", font=30)
        self.label.place(x=100, y=500)

        self.button = tk.Button(self, text="Browse...", width=10, height=2, command=lambda: self.get_contractor_file())
        self.button.place(x=1000, y=490)

        self.button = tk.Button(self, text="Upload", command=lambda: controller.show_frame("PageTwo"), width=10, height=2)
        self.button.place(x=1250, y=430)
0 Answers
Related