2014-07-10 82 views
0

您好我正在使用python Tkinter编写一个基本的GUI。我可以让它显示界面,但是当要求我的一个按钮调用子过程时,虽然没有错误报告,但GUI不加载。这里是按钮的代码:Tkinter程序无法加载

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() 

如果我没有在我的代码中包含按钮“D”,GUI会出现。奇怪的是,如果我包含按钮“D”并传递一个不存在的文件到subprocess.call中,GUI会出现,但是我收到一条错误消息,说文件不存在,如预期的那样。

为什么然后传递一个存在于目录中的程序导致程序不能运行,而没有传递错误消息?

非常感谢

+0

为命令你需要通过调用 – ambi

+0

./myprogram是可调用的,具有可执行状态 – brucezepplin

+0

你要通过一个可调用的Python对象作为'command'参数的值。你不这样做 - 你调用'subprocess.call()'函数,它立即执行外部脚本,并将该调用的_return value_作为命令传递。 – BlackJack

回答

1

你已经作为命令传递不是一个函数,但函数返回的是什么(当然这可能是一个函数)。 因此,而不是:

D = Tkinter.Button(root, text ="Generate variant fasta(s)", command = subprocess.call(['./myprogram.sh','B','C'],shell=True)).pack() 

你应该把它想:

def click_callback(): 
    subprocess.call(['./myprogram.sh','B','C'],shell=True) 

D = Tkinter.Button(root, text ="Generate variant fasta(s)", command = click_callback).pack() 
+0

好的谢谢,这工作。 – brucezepplin

1

使用

command = subprocess.call(['./myprogram.sh','B','C'],shell=True) 

运行subprocess和结果分配给command=

command=只期望函数名,而不()和参数(如AMBI说:蟒蛇callable元素)

大概subprocess正在运行,并且脚本不能运行的代码休息。

也许你需要

def myprogram() 
    subprocess.call(['./myprogram.sh','B','C'],shell=True) 

command = myprogram 

你真的需要子过程?

+0

非常感谢,这工作。 – brucezepplin