Tkinter程序未加载

2024-03-29 10:08:25 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在用pythontkinter编写一个基本的GUI。我可以让它显示界面,但是当要求我的一个按钮调用子进程时,GUI不会加载,尽管没有报告错误。以下是按钮的代码:

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”并将一个不存在的文件传递到子流程调用,GUI出现,但我收到一条错误消息,说文件不存在。你知道吗

那么,为什么传递目录中不存在的程序会导致程序不运行,而不传递错误消息呢?你知道吗

非常感谢


Tags: 文件代码text消息tkinter错误guibutton
2条回答

作为命令传递的不是函数,而是函数返回的内容(当然可能是函数)。 所以不是:

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

使用

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

运行subprocess,结果被分配给command=。你知道吗

command=只需要没有()和参数的函数名(正如ambi所说:pythoncallable元素)

可能subprocess正在运行,脚本无法运行其余代码。你知道吗

也许你需要

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

command = myprogram

你真的需要子流程吗?你知道吗

相关问题 更多 >