PyQt4运行外部.py文件

时间:2016-01-21 10:52:18

标签: python user-interface pyqt4 pyqt5

我正在使用PyQt4创建一个GUI,并希望它在按下按钮时调用另一个python文件。

这是GUI文件的形式:gui.py

# record push button
self.pbRec = QtGui.QPushButton("Record", self)
self.pbRec.setGeometry(QtCore.QRect(160, 210, 113, 32))
self.pbRec.clicked.connect(self.recordSetUp)

def recordSetUp(self):
    self.genericThread = GenericThread(self.record)
    self.genericThread.start()
    # disable button after click
    self.pbRec.setEnabled(False)

def record(self):
    print 'initiating record.py'
    currentPath = os.curdir
    filePath = currentPath + '/lib/record.py'
    os.system('python ' + filePath)
    print 'record.py finished'
    # re enable button
    self.pbRec.setEnabled(True)

record.py所做的是从外部连接的相机设备捕获图像,直到用户按下回车键。

以下是record.py的结束方式

# Keep this process running until Enter is pressed
print "Press Enter to quit..."
try:
    sys.stdin.readline()
except KeyboardInterrupt:
    pass
finally:
    controller.removeDevice(device)

这一切都运行正常,当我按下记录按钮时,它会加载record.py,然后按回车键进入终点。

但我无法从我的GUI按Enter键以使record.py停止。

有办法做到这一点吗?所以当我从gui调用外部文件时,我可以从gui而不是终端与它进行交互?

提前致谢。

0 个答案:

没有答案
相关问题