0

I was wondering how I'd be able to have a python file run another file provided from user selection with Tkinter. This is what I have so far, file selection work but I am unable to actually run the chosen file.

import os
from tkinter import filedialog
from tkinter import *

root = Tk()
root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select 
file",filetypes = (("python","*.py"),("all files","*.*")))
print(root.filename)

a = root.filename

print(a.rfind('/'))
b = 'python '
c = (a[(a.rfind('/')+1):])
d = (b+c)

print(d)
os.system(d)
Tom Callan
  • 65
  • 7
  • 1
    Possible duplicate of [How to run a python script from another python script and get the returned status code?](https://stackoverflow.com/questions/8724557/how-to-run-a-python-script-from-another-python-script-and-get-the-returned-statu) – Matthew Strawbridge Nov 24 '18 at 22:32

1 Answers1

0

On the last line try,

os.system("open "+d)

that might work...?

  • Congrats on your first answer. And welcome to stackoverflow. For this kind of suggestions, please use the comments feature. – ba_ul Nov 25 '18 at 00:06