PyQT关闭并重新打开应用程序

时间:2016-07-06 22:42:29

标签: python pyqt

以下代码中的按钮应该关闭程序窗口并重新打开它。 RESTART部分在不同的环境中运行良好,但是我无法在这个环境中工作。 知道我在这里缺少什么吗?非常感谢来自更多有经验的人的帮助。

import sys
import subprocess
from PyQt4 import QtCore, QtGui

class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):

        super(MainWindow, self).__init__(parent)

        self.win_widget = WinWidget(self)
        widget = QtGui.QWidget()
        layout = QtGui.QVBoxLayout(widget)
        layout.addWidget(self.win_widget)
        self.setCentralWidget(widget)

        self.statusBar().showMessage('Ready')

        self.setGeometry(300, 300, 450, 250)
        self.setWindowTitle('Test')  
        self.setWindowIcon (QtGui.QIcon('logo.png'))
        self.show()

class WinWidget (QtGui.QWidget) : 

    def __init__(self, parent): 

        super (WinWidget , self).__init__(parent)
        self.controls()
        self.grid_layout() 

    def controls(self):

        self.btn_newSearch = QtGui.QPushButton('New Search  ', self)
        self.btn_newSearch.clicked.connect(self.restart)
        self.btn_newSearch.setFont(QtGui.QFont('CourierNew', 12 , QtGui.QFont.Bold,False))

    def restart(self):
        self.close()
        subprocess.call("python" + "question.py  ", shell=True)

    def grid_layout (self) : 
        grid = QtGui.QGridLayout()
        grid.setSpacing(2)
        grid.addWidget(self.btn_newSearch , 1 , 1)
        self.setLayout(grid)

def main():

    app = QtGui.QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:1)

如果<?php $matches = array(); $data = '| years_active = 1960–70 | label = '; preg_match('/active(.*)label/', $data, $matches); var_dump($matches); 环境变量中包含python,则不需要PATH参数。您也可能不想使用shell=True,因为它会阻止

subprocess.call