2014-10-16 37 views
0

我有一个项目在工作,我们真正的开发人员没有时间来处理我需要的东西,所以我正在创建我的第一个GUI。tkinter按钮不打开所有批处理文件

它有两个按钮。点击后,他们运行一个批处理文件。批处理文件运行注册表文件,并运行软件可执行文件。它正常工作时,我的测试,但蝙蝠只跑了回音说...当我更换该批处理文件与下面的批次的“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() 
+0

你为什么认为这是一个tkinter问题?如果直接运行'subprocess',会发生什么? – jonrsharpe 2014-10-16 12:46:15

+0

看起来像差不多相同的错误。我不认为它是特定于tkinter,按钮的工作和gui是好的。我猜这个子进程命令有问题,但我不知道它究竟是什么。 – Thr1llhouse 2014-10-16 15:09:00

+0

在这种情况下,您可能会剥离与GUI有关的所有内容。看看http://stackoverflow.com/help/mcve和http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – jonrsharpe 2014-10-16 15:09:59

回答

0

所以我读了jon发布的博客,并能解决我的问题。 Tkinter是正确的,我的子进程是好的,我所要做的就是将.py放入一个带有.reg和.bat文件的文件夹中,并且工作正常。结束了改变开始批量只使用regedit/S以及...谢谢大家。

相关问题