E:\>E:\Python37\python.exe -m pip uninstall PyQt5
Uninstalling PyQt5-5.10.1:
Would remove:
E:\python37\lib\site-packages\pyqt5-5.10.1.dist-info\*
E:\python37\lib\site-packages\pyqt5\*
E:\python37\scripts\pylupdate5.exe
E:\python37\scripts\pyrcc5.exe
E:\python37\scripts\pyuic5.exe
Proceed (y/n)? y
Successfully uninstalled PyQt5-5.10.1
旧的 PyQt5 运行就出错, 所以先卸载:
然后安装新的:
E:>E:\Python37\python.exe -m pip install pyqt5
Collecting pyqt5
Downloading https://files.pythonhosted.org/packages/46/83/7c27aec708a1eb12812a
0b985eb42eebfe3bb87e294cdca1c4af308d2fa9/PyQt5-5.14.1-5.14.1-cp35.cp36.cp37.cp38
-none-win_amd64.whl (53.1MB)
3% |█ | 1.7MB 9.3kB/s eta 1:32:11
Operation cancelled by user
发现安装速度太慢, 所以去下载一个手动安装:
http://pypi.doubanio.com/packages/46/83/7c27aec708a1eb12812a0b985eb42eebfe3bb87e294cdca1c4af308d2fa9/PyQt5-5.14.1-5.14.1-cp35.cp36.cp37.cp38-none-win_amd64.whl#md5=81d3c49eb109cf1293025fe01cf66739
一切OK:
E:>E:\Python37\python.exe -m pip install d:\downloads\PyQt5-5.1
4.1-5.14.1-cp35.cp36.cp37.cp38-none-win_amd64.whl
Processing d:\downloads\pyqt5-5.14.1-5.14.1-cp35.cp36.cp37.cp38-none-win_amd64.w
hl
Collecting PyQt5-sip<13,>=12.7 (from PyQt5==5.14.1)
Downloading https://files.pythonhosted.org/packages/66/a6/3f1609f1a77445a088be
e7490229a4d430c9d0e1afd8ebd185fbc9c6aa57/PyQt5_sip-12.7.1-cp37-cp37m-win_amd64.w
hl (58kB)
100% |████████████████████████████████| 61kB
77kB/s
Installing collected packages: PyQt5-sip, PyQt5
Successfully installed PyQt5-5.14.1 PyQt5-sip-12.7.1
离线
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
ZetCode PyQt5 tutorial
In this example, we receive data from
a QInputDialog dialog.
Aauthor: Jan Bodnar
Website: zetcode.com
Last edited: August 2017
"""
from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit,
QInputDialog, QApplication)
import sys
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.btn = QPushButton('Dialog', self)
self.btn.move(20, 20)
self.btn.clicked.connect(self.showDialog)
self.le = QLineEdit(self)
self.le.move(130, 22)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Input dialog')
self.show()
def showDialog(self):
text, ok = QInputDialog.getText(self, 'Input Dialog',
'Enter your name:')
if ok:
self.le.setText(str(text))
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
拷贝几行代码: http://zetcode.com/gui/pyqt5/dialogs/
运行: E:\Python37\python.exe d:\8899\x.py
参考: http://zetcode.com/gui/pyqt5/
试一试, 完全OK
离线