def delFile(self, num):
if os.path.exists("quiz"+str(num)+".txt"):
os.remove("quiz"+str(num)+".txt")
tkinter.messagebox.showinfo("Removed!", "Quiz successfully Removed!")
else:
tkinter.messagebox.showinfo("Error!", "Quiz file not found!")
if os.path.exists("answer"+(num)+".txt"):
os.remove("answer"+(num)+".txt")
tkinter.messagebox.showinfo("Removed!", "Answers successfully Removed!")
else:
tkinter.messagebox.showinfo("Error!", "Answer file not found!")
delete = quizEdit("a")
root = Tk()
root.geometry("450x320")
root.title("Remove a text file")
label1 = Label(root, text = "What to remove?")
label1.place(x=70, y = 140)
entry1 = Entry(root)
entry1.place(x = 180, y = 140)
et = entry1.get()
button1 = Button(root, text = "Remove", command=lambda : delete.delFile(et))
button1.place(x=210, y=200)
root.mainloop()
I'm trying to make it so that the delFile method can delete a text file from the directory based on whatever is entered from the entry in the GUI. However when I press the button it just outputs the else clause messagebox.
delFile is a method of a class called quizEdit.