如何执行在python中运行的文件

问题描述 投票:-1回答:1

我一直在尝试制作一个tkinter游戏,一旦完成,它就会重新执行其自我。这是我尝试的代码:

from subprocess import run
.....
.....
.....
.....
run('python3 ' + __file__)

from subprocess import run
from os.path import dirname
.....
.....
.....
.....
run('python3 ' + dirname(__file__) + filename)

但是所有解决方案均无效。有没有一种方法可以让我的程序最后重新启动?谢谢!

python file subprocess
1个回答
0
投票
您可以通过将其放在循环中来重新启动程序:

def start(): ..... ..... ..... ..... while True: start()

© www.soinside.com 2019 - 2024. All rights reserved.