1

I want to run multi command lines by clicking different buttons using python GUI ?

for example I have button1 and button2 when I click button1 a command line will be excuted and when I press button2 another shell should be opened and new command line will be runned withour stopping the firat one.

I read about it but I didn't find the suitable code for that

What I wrote is the following:

   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() 
RSA
  • 79
  • 12
  • https://docs.python.org/3.4/library/multiprocessing.html – Jens Feb 03 '15 at 07:20
  • I saw this link but i didnt know how to use it in my code... It is my first time to do a gui using python @Jens – RSA Feb 03 '15 at 07:34

1 Answers1

0

subprocess.call() waits for the command to finish. Do not use it in command callbacks: it make the GUI unresponsive -- everything is frozen until call() returns.

To avoid blocking GUI, you could use subprocess.Popen() instead that returns as soon as the child process starts.

If you want to run each command in a new terminal window; see Execute terminal command from python in new terminal window?

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670