Reputation: 9782
Hi I am writing a basic GUI using python Tkinter. I can get it to show the interface, however when asking one of my buttons to call a subprocess, the GUI does not load, although there are no errors reported. here is the code for the buttons:
B = Tkinter.Button(root, text ="Reference fasta file", command = openfile).pack()
C = Tkinter.Button(root, text ="SNP file", command = openfile).pack()
D = Tkinter.Button(root, text ="Generate variant fasta(s)", command = subprocess.call(['./myprogram.sh','B','C'],shell=True)).pack()
If I do not include button "D" in my code, the GUI appears. Strangely if I include button "D" and pass a file that does not exist into subprocess.call, the GUI appears, but I get an error message saying file does no exist as expected.
why then does passing a program which does exist in the directory cause the program not to run, without an error message being passed?
Thanks very much
Upvotes: 0
Views: 108
Reputation: 1316
You've passed as command not a function but what is returned by a function (which of course may be a function). So instead of:
D = Tkinter.Button(root, text ="Generate variant fasta(s)", command = subprocess.call(['./myprogram.sh','B','C'],shell=True)).pack()
you should call it like:
def click_callback():
subprocess.call(['./myprogram.sh','B','C'],shell=True)
D = Tkinter.Button(root, text ="Generate variant fasta(s)", command = click_callback).pack()
Upvotes: 1
Reputation: 143001
Using
command = subprocess.call(['./myprogram.sh','B','C'],shell=True)
you run subprocess
and result is assigned to command=
.
command=
expect only function name without ()
and arguments (as ambi said: python callable
element)
Probably subprocess
is running and script can't run rest of code.
Maybe you need
def myprogram()
subprocess.call(['./myprogram.sh','B','C'],shell=True)
command = myprogram
Do you really need subprocess ?
Upvotes: 1