I wrote a script (test.py) for Data Analysis. Now I'm doing a GUI in PyQt. What I want is when I press a button 'Run', the script test.py will run and show the results (plots).
I tried subprocess.call('test1.py')
and subprocess.Popen('test1.py')
but it only opens the script and don't run it.
I also tried os.system
, doesn't work either.
The script below is not complete (there are more buttons and functions associated but is not relevant and aren't connect to the problem described).
I'm using Python 3.6 on Spyder and PyQt5.
Is there any other function or module that can do what I want?
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50, 50, 500, 300)
self.setWindowTitle("TEMP FILE")
self.home()
def home (self):
btn_run = QPushButton("Run", self)
btn_run.clicked.connect(self.execute)
self.show()
def execute(self):
subprocess.Popen('test1.py', shell=True)
subprocess.call(["python", "test1.py"])
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
GUI = Window()
app.exec_()