How to open a program from my computer in python?
Im making a window in tkinter and I can't figure out how to run an external program in python. I am using the full path and am getting no errors, the file is just not loading.
os.startfile(path) but that doesn't open the file.
Here is my code:
from tkinter import * from tkinter import ttk import os def run_selected(): if ver.get() == "Test": os.startfile(path) master = Tk() ver = ttk.Combobox(master, state="readonly", values=["Test"]) ver.pack() Button(master, text="Run", command=run_selected).pack() master.mainloop()
How do I fix this so that I can open the file?
One of the ways could be
import subprocess def run_selected(): if ver.get() == "Test": subprocess.run([path], check=True) # e.g. subprocess.run(["ls","-ltr"], check=True)
However, since you are spawning it from Tkinter, you could spawn it from a different thread (unless process ends within milliseconds), else, the default Tkinter thread will get busy and the UI will appear frozen
have you tried "import os"?
import os os.startfile(path/.file.py)