HELO
I am new to Python and learning a lot thanks to Stackoverflow, but at the moment I am stuck at this simple task where I was sure I would resolve it myself but spent few hours looking around.
I have Tkinter GUI with a button, where if pressed it will look for such name in specific file path and if it finds "Check For Updates", it will run it else it will do nothing as expected.
import tkinter as tk
import os
root = tk.Tk()
button = tk.Button(root, text="Open", height=1, width=25, borderwidth="2", command=lambda: openupdt())
button.grid()
def openupdt():
os.startfile(r"C://ProgramData//Microsoft//Windows//Start Menu//Programs//Java//Check For Updates")
root.mainloop()
Here I tried to use IF statement but it seems like I am doing something wrong. If no file in such path is found I would like it to print message or do what ever is instructed.
def openupdt():
os.startfile(r"C://ProgramData//Microsoft//Windows//Start Menu//Programs//Java//Check For Updates")
if openupdt == False:
print("No such file")
gives me an error "The system cannot find the file specified:" as if it fully ignores IF statement
Thank you.
if openupdt == False:inside of the definition of a function namedopenupdtdoesn't make sense. What is that supposed to do? In any event, you can usetry ... exceptto catch errors which occur when you try to open a file.button = tk.Button(root, text="Open", height=1, width=25, borderwidth="2", command=lambda: foo() if os.path.exists(file_path) print("No such file"))