Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.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
Python 使用Qt(PyQt)中的按钮启动roslaunch文件_Python_Qt_Pyqt_Ros_Qtgui - Fatal编程技术网

Python 使用Qt(PyQt)中的按钮启动roslaunch文件

Python 使用Qt(PyQt)中的按钮启动roslaunch文件,python,qt,pyqt,ros,qtgui,Python,Qt,Pyqt,Ros,Qtgui,我正在尝试为我创建的基于ROS的程序制作GUI。我想做一个按钮,启动roslaunch文件。有这个命令吗?或者,一个示例程序可能会有所帮助。如果您想使用,您可以创建一个QPushButton,单击该按钮将执行正常的roslaunch命令。您可以设置在按下按钮时调用的函数(使用单击的.connect())。在该函数中,您可以使用QProcess运行外部可执行文件,在您的情况下,该文件将是: roslaunch my_launch_file.launch或您通常在终端中运行以启动程序的任何程序 下面

我正在尝试为我创建的基于ROS的程序制作GUI。我想做一个按钮,启动roslaunch文件。有这个命令吗?或者,一个示例程序可能会有所帮助。

如果您想使用,您可以创建一个
QPushButton
,单击该按钮将执行正常的roslaunch命令。您可以设置在按下按钮时调用的函数(使用
单击的.connect()
)。在该函数中,您可以使用
QProcess
运行外部可执行文件,在您的情况下,该文件将是:
roslaunch my_launch_file.launch
或您通常在终端中运行以启动程序的任何程序

下面是一个对我有用的简单脚本(ubuntu 14.04,ros indigo):

如果需要,您可能可以将PyQt4切换到上面的PyQt5

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MainLauncher( QWidget ):

    def __init__(self):
        QWidget.__init__(self)
        mainLayout = QGridLayout()
        self.launchButton = QPushButton( "LAUNCH" )
        self.launchButton.clicked.connect( self.onClick )
        mainLayout.addWidget(self.launchButton, 1, 1)
        self.setLayout( mainLayout )

    def onClick(self):
        ROS_PROGRAM = QProcess(self)
        print "Launching..."
        program = 'roslaunch my_launch_file.launch'
        ROS_PROGRAM.start(program)

if __name__ == '__main__':

    app = QApplication( sys.argv )
    mainLauncher = MainLauncher()
    mainLauncher.show()
    sys.exit(app.exec_())