i'm totally new to python and I'm trying to make an easy GUI with tkinter that should take a name of a textfile in an entry widget, and when you click a button the text in the entry should be passed to a function handling the file.
This is a snippet of my code:
win = Tk() win.title("Upprepade ord") textFileButton = Button(win, text = "Läs in") textFileButton.grid(row = 2, column = 2) textFile = StringVar() textFileEntry = Entry(win, textvariable = textFile) textFileEntry.grid(row = 1, column = 2) textFileLabel = Label(win, text = "Textfil") textFileLabel.grid(row = 0, column = 2) textFileButton.configure(command = mainObject.file2List(textFile.get())) win.mainloop()
The problem is that the file2List function checks if the file passed exists, and produce an error if it doesn't.
This error now shows as soon as I run the program, not after passing a faulty filename.
So, how do prevent the function being run until i click the button?