首页 > 解决方案 > 通过 python linux 运行 python 脚本

问题描述

我想通过 GUI 执行一个 Python 文件。所以我正在使用以下行来运行该脚本。它在 Windows 上运行良好。

GButton_330=tk.Button(root)
GButton_330["bg"] = "#efefef"
ft = tkFont.Font(family='Times',size=10)
GButton_330["font"] = ft
GButton_330["fg"] = "#000000"
GButton_330["justify"] = "center"
GButton_330["text"] = "Start"
GButton_330.place(x=340,y=170,width=70,height=25)
GButton_330["command"] = lambda: os.system('run.py')

但是当我在 Linux 上尝试时,它会说run.py: not found. 我无法弄清楚这个问题。run.py与 位于同一目录中GUI.py

标签: pythontkinter

解决方案


你可以尝试做

os.system('./run.py')

或者如果那不起作用那么

os.system('python3 run.py') # or just python for python 2

推荐阅读