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)
1

1 Answer 1

0

On the last line try,

os.system("open "+d)

that might work...?

Sign up to request clarification or add additional context in comments.

1 Comment

Congrats on your first answer. And welcome to stackoverflow. For this kind of suggestions, please use the comments feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.