Is there a way to close a program using Python? I want to create a GUI that opens a program with a specific path when pressing a button, and then closes that program when pressing a different button. I want to open and close an STL file that uses the Windows program app Print 3D to view the file. I am able to open the file but can't close it.
Please see my code below:
from tkinter import *
import os
#Works to open program
def openProg():
os.startfile(r'C:\Users\me\Desktop\sphere.stl')
#Does not work to close the program
def closeProg():
os.close(r'C:\Users\me\Desktop\sphere.stl')
root = Tk()
root.geometry('370x260')
root.title('File Remote')
B1 = Button(root, text= 'OPEN', width=24, height =12, command=openProg).place(x=5, y=5)
B2 = Button(root, text= 'CLOSE', width=24, height =12, command=closeProg).place(x=187, y=5)
root.mainloop()