Execute external program in Tk Python 2.7
Hello I'm beginning to learn how to use python to develop some tasks in the lab.
I'm trying to learn how to use the Tk module in Python 2.7 but can't figure out how to execute an external program and make it work.
Here is my code:
import sys
from Tkinter import *
import tkFileDialog
from tkFileDialog import askopenfilename
import os
fasta= ""
lista = ""
window = Tk()
window.title("Sequence extractor")
def callback():
fasta= askopenfilename()
lista = askopenfilename()
print fasta
print lista
return fasta,lista
errmsg = 'Error!'
but_fas = Button(text='FASTA Open', command=callback).pack(fill=X)
but_lis = Button(text='Lista Open', command=callback).pack(fill=X)
window.mainloop()
call = ("c:\Python_programs\Seq_extractor.py -l"+ lista+"-f " + fasta)
print call
os.system (call)
Is it possible that there is a problem with the order of the commands?
• 5,777 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Is Seq_extractor.py your external script you want to execute? Not sure about use in Tkinter, but os.system is not the prefered method. You should have a look at the subprocess module.
Yes, is Seq_extractor.py.
I have looked for the subprocess module but does not work.
How about using execfile()?
subprocess.call() does work, use the shlex module to properly format your arguments
subprocess.call(shlex.split(call))Oh and the worst thing you can say is "it doesn't work". Tell us what doesn't work, the error message,...
I'm so sorry, I will take it into acount for future questions.
Here is the error: