tkinter按钮无法打开所有批处理文件
我在工作上有一个项目,我们的真正开发者没有时间帮我,所以我正在创建我的第一个图形用户界面(GUI)。
这个界面有两个按钮,点击后会运行一个批处理文件。这个批处理文件会运行一个注册表文件,然后再运行软件的可执行文件。测试的时候一切都很顺利,但我原来的批处理文件只是在输出“Hello World!”这句话……当我把那个批处理文件换成下面的代码时:
start /d "C:\Cogent\cls.chd\" cls.reg
SLEEP 5
start /d "C:\Cogent\cls.chd\bin\" CLSMain.exe
我运行同样的.py文件,却出现了以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Users\A32DZZZ\Desktop\LivescanMonrowFinal.py", line 31, in run1
process=subprocess.Popen("launch.bat", cwd=r"C:\\Cogent\\cls.chd")
File "C:\Python33\lib\subprocess.py", line 824, in __init__
restore_signals, start_new_session)
File "C:\Python33\lib\subprocess.py", line 1118, in _execute_child
raise WindowsError(*e.args)
FileNotFoundError: [WinError 2] The system cannot find the file specified"
有没有人能告诉我,我到底哪里没理解清楚?我的图形用户界面如下:
from tkinter import *
import subprocess
master = Tk()
master.title("Monroe Livescan Version Selector")
master.geometry("400x166")
#Menu construction
menubar=Menu(master)
filemenu = Menu(menubar,tearoff = 0)
filemenu.add_command(label="Close")
menubar.add_cascade(label="File",menu=filemenu)
helpmenu = Menu(menubar,tearoff = 0)
helpmenu.add_command(label="Help Docs")
helpmenu.add_command(label="About")
menubar.add_cascade(label="Help",menu=helpmenu)
master.config(menu=menubar)
#Define run function for first Livescan package.
def run1():
process=subprocess.Popen("launch.bat", cwd=r"C:\\Cogent\\cls.chd")
def run2():
process=subprocess.Popen("launch.bat", cwd=r"C:\\Cogent\\cls.iafis")
#Define the button geometry and commands to run.
b1 = Button(master, text='Child ID', command=run1)
b1.pack(padx=5, pady=5)
b1.config(height=4, width=45)
b2 = Button(master, text='IAFIS', command=run2)
b2.pack(padx=5, pady=5)
b2.config(height=4, width=45)
mainloop()
1 个回答
0
我看了jon发的博客,终于解决了我的问题。Tkinter是没问题的,我的子进程也没问题,关键是我只需要把.py文件放到一个和.reg、.bat文件在同一个文件夹里,就可以正常工作了。最后我还把批处理文件里的启动命令改成了直接用regedit /S,感谢大家的帮助。