有人可以查看我的代码在哪里吗?
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QFormLayout, QLineEdit, QComboBox, QSpinBox, QGroupBox, QVBoxLayout, QDialogButtonBox
class MyForm(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.first = QLineEdit("Name")
self.secnd = QLineEdit("Surname")
self.gendr = QComboBox()
self.gendr.addItems(['Male','Female','Shemale'])
self.age = QSpinBox()
self.age.setMinimum(15)
self.fgLayout = QFormLayout()
self.fgLayout.addRow('First', self.first)
self.fgLayout.addRow('Second', self.secnd)
self.fgLayout.addRow('Gender', self.gendr)
self.fgLayout.addRow('Age', self.age)
self.setLayout(self.fgLayout)
self.setWindowTitle("My Form")
self.setGeometry(500,300,250,150)
if __name__ == "__main__":
def run_app():
app = QtWidgets.QApplication(sys.argv)
mainWin = MyForm()
mainWin.show()
app.exec_()
run_app()
我运行它,但结果是空白窗口。除了通过PyQt5脚本查看示例之外,我找不到错误。也许我以错误的方式使用了某些组件?
我已经更改了建议的设置,如此链接[https://github.com/spyder-ide/spyder/wiki/How-to-run-PyQt-applications-within-Spyder
]所述,但仍然出现错误:
\Anaconda3\lib\site-packages\ipykernel\parentpoller.py:116: UserWarning: Parent poll failed. If the frontend dies,
the kernel may be left running. Please let us know
about your system (bitness, Python, etc.) at
ipython-dev@scipy.org
ipython-dev@scipy.org""")
Kernel died, restarting
这一定是一些安装问题。我刚刚卸载了Anaconda的先前版本并安装了一个新版本(Windows 7 Sp1)。我的代码也可能出了点问题,因为上述链接中的示例工作正常;我刚刚添加了一些功能。