-1
我開始學習如何使用python,並需要爲實驗室項目開發一些應用程序。Python 2.7 Tk filedialog調用外部程序
我想創建一個GUI來選擇我想作爲參數傳遞給另一個程序的幾個文件。 GUI部分似乎工作,但是當我嘗試使用Popen方法調用外部腳本,但據稱通過GUI捕獲的變量未傳遞給Popen調用時。
我請求你的建議,以解決這個問題,因爲它似乎仍然有點超出我目前的知識,我真的需要使用Tk/GUI作爲此項目的接口。
這裏是我的代碼:
def button_fasta_callback():
fasta = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a FASTA')
if fasta != None:
data_fasta = fasta.read()
fasta.close()
def button_lista_callback():
lista = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a list')
if lista !=None:
data_lista = lista.read()
lista.close()
#####Create the buttons#######
root = Tk()
root.title("Sequence extractor")
button_fasta = Button(root,
text="Choose FASTA",
command=button_fasta_callback)
button_fasta.pack(padx=150, pady=50)
button_lista = Button(root,
text="Choose a list",
command=button_lista_callback)
button_lista.pack(padx=150, pady=50)
entry = Entry(root, width=50)
root.mainloop()
caller = Popen(['C:\\Python_programs\\Seq_extractor.py', '-l', lista, '-f', fasta])
謝謝大家!