我正在創建一個GUI,其中我從用戶那裏獲得輸入(文件名)。使用python創建GUI(對文件進行操作)
然後我必須在該文件上運行一些shell腳本,並分別顯示每個腳本的輸出。
我有點卡在子進程模塊。每次運行時,都會報錯。
另一件事是,我如何創建一個全局字符串變量,因爲我無法訪問我在另一個函數中使用的變量。
CODE:
import sys
from Tkinter import *
from tkFileDialog import *
import subprocess
import os
FileName = ""
FilePath = ""
def browse():
Tk().withdraw()
FilePath = askopenfilename(filetypes = (("ApkFiles","*.apk"),("All files", "*")))
print FilePath
Parts = FilePath.split("/")
FileName = Parts[-1]
name = str(FileName)
#print FileName
def process():
print FileName
#subprocess.call("cat ", FileName, shell=True)
#Content = open(self.filename,"r").readlines()
#print Content
#subprocess.call("command-name-here")
#output = subprocess.call(["/path/to/command", "arg1", "-arg2"])
#subprocess.Popen("ls", stdout=subprocess.PIPE, shell=True)
#subprocess.call ("ls")
subprocess.call (['cp filename /Home/dinesh/Base/ApkFiles/'])
subprocess.call (['cd /Home/dinesh/Base'])l
subprocess.call (['./AppSplit 0.1 0.1 0.8'])
Status = subprocess.call (["AppSplit.sh" ,"filename"])
#exit (Status)
# exit (0)
gui = Tk() #create an object
gui.title("Select an app to be clustered")
gui.geometry("700x400")
GuiLabel1 = Label(gui,text="Select an app to be clustered").grid(row=0 , column=4)
GuiLabel2 = Label(gui,text="ApkFile").grid(row=3 ,column=3)
bar=Entry(gui).grid(row=3, column=4)
button1= Button(gui, text="Browse", command = browse).grid(row=3, column=5)
button2= Button(gui, text="Cluster", command = process).grid(row=4, column=5)
gui.mainloop() #necessary for windows
什麼是你'AppsSplit.sh'他們內心世界的關鍵字?如果可能的話,只需將你的shell腳本移植到Python。更容易維護。 – ghostdog74 2014-10-30 07:01:09