我有一个项目在工作,我们真正的开发人员没有时间来满足我的需求,因此我正在创建我的第一个GUI。
它有两个按钮。单击时,它们运行批处理文件。批处理文件运行注册表文件,并运行软件可执行文件。它在我测试时工作正常,但是.bat只运行一个回音说“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"
谁能告诉我,我显然不理解?我的GUI如下:
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()
答案 0 :(得分:0)
所以我读了jon发布的博客,能够解决我的问题。 Tkinter是正确的,我的子进程很好,我所要做的就是将.py移动到一个包含.reg和.bat文件的文件夹中,并且它有效。结束了将批处理中的开始更改为仅使用regedit / S ...感谢所有。