开发者

Open File with Python

I am writing a tkinter program that is kind of a program that is like a portfolio and opens up other programs also writen in python. So for example i have FILE_1 and FILE_2 and i want to write a program that onced clicked on a certain button opens either FILE_1 or FILE_2. i dont need help with the look like with buttons just how to wirte a function that opens a program

This is the code i used:

from Tkinter import *
import subprocess

master = Tk()

def z():开发者_JS百科
    p=subprocess.Popen('test1.py')
    p.communicate()


b = Button(master, text="OK", command=z)
b.pack()



mainloop()


Hook the button up a callback which calls subprocess.Popen:

import subprocess
p=subprocess.Popen('FILE_1.py')
p.communicate()

This will try to run FILE_1.py as a separate process. p.communicate() will cause your main program to wait until FILE_1.py exits.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜