嗨,我在Tkinter工作,并建立了一个框架,要求打开一个文件,然后打开该文件以运行文件,
import subprocess
import pandas as pd
import Tkinter as tk
class MonthlyMenu(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
self.controller = controller
self.browsefile = tk.StringVar()
self.fileentry = tk.Entry(self, textvariable = self.browsefile,).grid(row=1,column=1,sticky=tk.W+tk.E)
self.submitFile = tk.Button(self,text="Ok",command=self.openFile).grid(row=1,column=2,sticky = tk.W+tk.E)
def openFile(self):
self.browsefile.get()
filename = self.browsefile.get()
df = pd.read_excel(filename, sheename="Sheet1",parse_col=0)
titles = list(df.columns)
for col in titles:
sa_command = "C:\\X12\\x12a.exe %s" % (col)
process = subprocess.Popen(sa_command,stdout=subprocess.PIPE)
process.wait()
但是运行带有子进程的可执行文件的代码的最后部分没有运行。该for循环中还有其他代码可以运行并构建正确的文件以运行该可执行文件,但我认为没有必要显示所有内容。我尝试过将子流程代码从for循环中打破,然后手动传递标题,但这也没有用。
我在该for循环中创建的所有其他文件均正常工作,并且仅使用这些文件单独运行了子流程代码(在仅包含该代码的.py文件中),然后该文件即可正常工作。我想知道是否有人知道在试图导致该问题的类中运行它是否是一个问题,或者我只是错过了什么。
好的,我不确定回答我自己的问题有多好,我保证在发布问题之前,我已经尝试过一段时间了。
但是我所做的只是在命令中将目录添加到文件中,这没关系,因为它们始终位于同一目录中。因此将其更改为:
sa_command = "C:\\X12\\x12a.exe C:\\X12\\%s" % (col)
该代码现在可以正常工作(我还意识到我以前错误地复制了我的代码,并且在字符串内使用了“ col”,但该字符串无效)。
编辑:我现在意识到,因为我正在运行的.py文件不在C:\ X12目录中,所以该命令正在.py文件的目录中而不是在带有可执行文件的目录中寻找适当的文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句