Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tkinter 能够在进程运行时在基于python的gui中选择按钮_Tkinter - Fatal编程技术网

Tkinter 能够在进程运行时在基于python的gui中选择按钮

Tkinter 能够在进程运行时在基于python的gui中选择按钮,tkinter,Tkinter,我是python新手,我一直想用python tkinter运行一个可执行文件,按下一个按钮,可执行文件将使用os.system运行,然后按下另一个按钮停止,我编写了一个c代码,使用kill命令停止可执行文件,并在python gui中运行可执行文件,但一旦进程运行,我就无法单击其他按钮。如何停止它,我已将代码粘贴到下面,请帮助我解决此问题 from Tkinter import * import os import sys def init(): os.system('./a.ou

我是python新手,我一直想用python tkinter运行一个可执行文件,按下一个按钮,可执行文件将使用os.system运行,然后按下另一个按钮停止,我编写了一个c代码,使用kill命令停止可执行文件,并在python gui中运行可执行文件,但一旦进程运行,我就无法单击其他按钮。如何停止它,我已将代码粘贴到下面,请帮助我解决此问题

from Tkinter import * 
import os
import sys

def init():
    os.system('./a.out')


def lena():
    os.system('./test')

WINDOW_W = 300
WINDOW_H = 80

def createDisplay():
 global tk
 global btn
 # create the tk window - within which
 # everything else will be built.
 tk = Tk()
  #Add a canvas area ready for drawing on
 canvas = Canvas(tk, width=WINDOW_W, height=WINDOW_H)
 canvas.pack()
 #Add an exit button
 btn = Button(tk, text="lena", command=lena)
 btn.pack()

 btn1 = Button(tk, text="optimist", command=lambda:os.system('./optimist'))
 btn1.pack()
 btn2 = Button(tk, text="text",command=init)
 btn2.pack()
 btn3 = Button(tk, text="exit", command=terminate)
 btn3.pack()
 # Start the tk main-loop (this updates the tk display)
 tk.mainloop()

def terminate():
 global tk
 tk.destroy()

def main():
 createDisplay()

if __name__ == '__main__':
 main()

os.system
是一个阻塞函数,在调用的命令完成之前,程序中不会发生任何其他事情

考虑改用

使用子进程,您调用的脚本将作为单独的进程在后台运行

import subprocess
subprocess.Popen('./test')