gpt4 book ai didi

python-3.x - 从另一个 'frozen' python 脚本调用 python 脚本

转载 作者:行者123 更新时间:2023-12-01 04:44:03 26 4
gpt4 key购买 nike

我有一个简单的脚本可以调用其他脚本并且工作正常:

def demandesparbranche():
os.system('python Sources/x.py')


def demandesparlogiciel():
os.system('python Sources/xx.py')


def demandeshcapprouvees():
os.system('python Sources/xxx.py')


def challengesreussis():
os.system('python Sources/xxxx.py')

我的想法是使用 tkinter 添加 GUI 并卡住此代码(使用 pyinstaller)并将其用作一组按钮来启动以这种方式保持可修改的脚本。我试过了,但它不起作用,这是合乎逻辑的,因为在没有安装 python 的计算机中,命令“python”显然是未知的。该代码在我安装了 python 的计算机上运行良好。

这是否可能使用另一种形式的脚本调用?我的意思是:如何调用 pyinstaller 卡住的 Python 解释器而不是系统解释器?

最佳答案

所以,我找到了解决方案:

我没有使用“os”模块调用脚本,而是导入了所需的脚本:

from xscript import x

并通过按钮直接调用它:
tk.Button(mainframe, width=25, text="Something", command=x, bg='light grey')\
.grid(column=1, row=1, sticky=W)

2个警告:

文件名 初始化 .py 需要在同一目录中;导入的脚本也一样。

关于python-3.x - 从另一个 'frozen' python 脚本调用 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48405755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com