E:\Python37>E:\Python37\python.exe -m pip install PyQt4
Collecting PyQt4
Could not find a version that satisfies the requirement PyQt4 (from versions:)
No matching distribution found for PyQt4
显示PyQt4 不在服务器上了, 安装 PyQt5 是正常的。
离线
打开 https://www.lfd.uci.edu/~gohlke/pythonlibs/
找到
PyQt4 (discontinued): a set of bindings for the Qt4 application framework.
Requires write access to the site-packages\PyQt4 folder to create qt.conf.
PyQt4‑4.11.4‑cp37‑cp37m‑win_amd64.whl
PyQt4‑4.11.4‑cp37‑cp37m‑win32.whl
PyQt4‑4.11.4‑cp36‑cp36m‑win_amd64.whl
PyQt4‑4.11.4‑cp36‑cp36m‑win32.whl
PyQt4‑4.11.4‑cp35‑cp35m‑win_amd64.whl
PyQt4‑4.11.4‑cp35‑cp35m‑win32.whl
PyQt4‑4.11.4‑cp34‑cp34m‑win_amd64.whl
PyQt4‑4.11.4‑cp34‑cp34m‑win32.whl
PyQt4‑4.11.4‑cp27‑cp27m‑win_amd64.whl
PyQt4‑4.11.4‑cp27‑cp27m‑win32.whl
我下载的是第一个: https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/PyQt4-4.11.4-cp37-cp37m-win_amd64.whl
安装:
E:\Python37>E:\Python37\python.exe -m pip install D:\Downloads\PyQt4-4.11.4-cp37-cp37m-win_amd64.whl
Processing d:\downloads\pyqt4-4.11.4-cp37-cp37m-win_amd64.whl
Installing collected packages: PyQt4
Successfully installed PyQt4-4.11.4
离线
来一个测试程序:
import sys
from PyQt4 import QtCore, QtGui
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
label = QtGui.QLabel("Hello World")
label.show()
sys.exit(app.exec_())
离线
import sys
from PyQt4 import QtGui
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
label = QtGui.QLabel("Hello World")
w.addWidget(label)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
离线
import sys
from PyQt4 import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.setToolTip('This is a <b>QWidget</b> widget')
btn = QtGui.QPushButton('Button', self)
btn.setToolTip('This is a <b>QPushButton</b> widget')
btn.resize(btn.sizeHint())
btn.move(50, 50)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Tooltips')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
离线