I have been experimenting with PyQt5 and testing very basic examples I've found online. I'm running this using anaconda spyder and python 3.7. The first time I run the code, the window appears fine and how I'd expect it to look. But the second time I try to run it, the window doesn't appear at all, it looks like my IPython console restarts and I have to manually terminate the code to get it to respond. I suspected it was because I wasn't terminating properly in the code but I've tried multiple ways to terminate including sys.exit()
, exit
, quit
, making a class and app=QApplication(sys.argv)
followed by sys.exit(app.exec_())
, etc. I still get the same issue. What could it be
Here's some examples I tried
Ex:
import sys
from PyQt5.QtWidgets import QPushButton, QApplication, QGridLayout, QVBoxLayout, QWidget, QGroupBox
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
layout.addWidget(QPushButton('Top'))
layout.addWidget(QPushButton('Bottom'))
window.setLayout(layout)
window.show()
app.exec_()
Another Example:
app = QApplication([])
window=QWidget()
layout=QGridLayout()
groupbox=QGroupBox("Box")
vbox=QVBoxLayout()
vbox.addWidget(QPushButton("Button"))
groupbox.setLayout(vbox)
layout.addWidget(groupbox, 0, 0)
window.setLayout(layout)
window.show()
app.exec_()