Python GUI 运行 在不同的 shell 中同时使用多个命令行
Python GUI running multi command lines at the same time in different shells
我想 运行 通过使用 python GUI 单击不同的按钮来使用多个命令行?
例如,我有 button1 和 button2,当我单击 button1 时,命令行将被执行,当我按下 button2 时,另一个 shell 应该被打开,新的命令行将 运行ned withoutour stopped第一个。
我读到了它,但没有找到合适的代码
我写的是这样的:
class Application(Frame):
"""A GUI """
def __init__(self,master):
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
#create first button
self.button = Button(self, text="roscore", command=self.roscore)
self.button.grid()
#create first button 1
self.button1 = Button(self, text="rqt plot", command=self.open_rqt)
self.button1.grid()
def open_rqt(self):
call(["rosrun", "rqt_plot", "rqt_plot"])
def roscore(self):
call(["roscore"])
root = Tk()
root.title("GUI")
root.geometry("1000x1000")
app = Application(root)
root.mainloop()
subprocess.call()
等待命令完成。不要在 command
回调中使用它:它会使 GUI 无响应——一切都被冻结,直到 call()
returns.
为避免阻塞 GUI,您可以在子进程启动后立即使用 subprocess.Popen()
而不是 returns。
如果你想运行新终端中的每个命令window;参见 Execute terminal command from python in new terminal window?
我想 运行 通过使用 python GUI 单击不同的按钮来使用多个命令行?
例如,我有 button1 和 button2,当我单击 button1 时,命令行将被执行,当我按下 button2 时,另一个 shell 应该被打开,新的命令行将 运行ned withoutour stopped第一个。
我读到了它,但没有找到合适的代码
我写的是这样的:
class Application(Frame):
"""A GUI """
def __init__(self,master):
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
#create first button
self.button = Button(self, text="roscore", command=self.roscore)
self.button.grid()
#create first button 1
self.button1 = Button(self, text="rqt plot", command=self.open_rqt)
self.button1.grid()
def open_rqt(self):
call(["rosrun", "rqt_plot", "rqt_plot"])
def roscore(self):
call(["roscore"])
root = Tk()
root.title("GUI")
root.geometry("1000x1000")
app = Application(root)
root.mainloop()
subprocess.call()
等待命令完成。不要在 command
回调中使用它:它会使 GUI 无响应——一切都被冻结,直到 call()
returns.
为避免阻塞 GUI,您可以在子进程启动后立即使用 subprocess.Popen()
而不是 returns。
如果你想运行新终端中的每个命令window;参见 Execute terminal command from python in new terminal window?