【发布时间】:2017-05-30 18:10:32
【问题描述】:
您好,我在 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 文件中),然后它可以正常工作。我想知道是否有人知道尝试在导致此问题的类中运行它是否存在问题,或者我是否只是遗漏了一些东西。
【问题讨论】:
标签: python python-2.7 tkinter subprocess exe