次のコードのボタンは、プログラムウィンドウを閉じてから再び開くようになっています。 RESTARTパートは別のコンテキストではうまく動作しますが、このワークフローでは機能しません。 私はここで何が不足していると思いますか?より多くの経験者からの助けが大いに感謝されるでしょう。PyQTを閉じてアプリケーションを開く
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()
をブロックしますので、あなたはまた、おそらく、
subprocess.call
を使用したくないあなたはスペースが不足しているように見え '「パイソン」+「question.pyは、」' '「pythonquestion.py」' –ブレンダンに等しいです。 、 ご回答有難うございます。 Sorrt、しかし私はそれに従うことができませんでした:正しい構文は何でしょうか? – rainer