赞
踩
PyQt5是Python构建跨平台应用程序的工具包,PyQt5 Reference Guide是对应的开发文档。
Qt是C++跨平台的类库,实现访问桌面应用程序和移动系统的高级别访问。包括本地和远程定位服务,NFC和蓝牙连接,基于Google Chromium web浏览器,以及传统UI的开发。
PyQt5是Python绑定Qt v5的全方面集合,已经实现超过35个模块,并使Python能够在所有以C++作为开发语言的平台上被使用。
PyQt5也可以嵌入到基于C++开发的英语程序,允许用户配置或者增强这些应用程序的功能。
PS C:\Users\Michael> python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5 >>> help(PyQt5) Help on package PyQt5:
NAME
PyQt5
PACKAGE CONTENTS
QAxContainer
Qt
QtBluetooth
QtCore
QtDBus
QtDesigner
QtGui
uic (package)
FILE
(built-in)
PS C:\> pip install PyQt5
Collecting PyQt5
Using cached PyQt5-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-none-win_amd64.whl (56.9 MB)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in python\lib\site-packages (from PyQt5) (12.8.1)
Installing collected packages: PyQt5
Successfully installed PyQt5-5.15.2
PS C:\> pip uninstall PyQt5
Proceed (y/n)? y
Successfully uninstalled PyQt5-5.15.2
The Python Package Index (PyPI) is Python以社区形式开发的应用软件库,提供给第三方免费使用。其中pip是PyPA推荐的用于安装Python软件包的工具。
pip install pip
安装PyQt5-tools程序包
PS C:> pip install PyQt5-tools
designer设计器在Python\Lib\site-packages\qt5_applications\Qt\bin 目录下
PyCharm集成QTDesigner的Tool Setting设置如下:
Program----D:\Python\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
Arguments----$FileName$ -o $FileNameWithoutExtension$.py 或者 缺省
Working dirctory----$ProjectFileDir$ 或者 D:\Python\Lib\site-packages\qt5_applications\Qt\bin
PyCharm集成QTDesigner的Tool Setting设置如下:
Program----D:\Python\Scripts\pyuic5.exe
Arguments----$FileName$ -o $FileNameWithoutExtension$.py 或者 缺省
Working dirctory----$ProjectFileDir$ 或者 D:\codetool\Python\Scripts
Run——External Tools——External Tools Configurations——Program——New
Run——External Tools——External Tools Configurations——Program——New
通过designer设计界面,保存成ui文件,然后通过pyuic转化成py文件。用户名和密码框选择Line Edit 当行文本框,而不是Text Edit多行文本框。
self.lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
pyuic5 -o C:\temp\login.py C:\temp\login.ui
附上一段代码,以供参考。
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class loginForm(object):
def setupUi(self, loginForm):
loginForm.setObjectName("loginForm")
loginForm.setWindowModality(QtCore.Qt.ApplicationModal)
loginForm.resize(595, 421)
font = QtGui.QFont()
font.setFamily("微软雅黑 Light")
font.setPointSize(11)
loginForm.setFont(font)
loginForm.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
loginForm.setLocale(QtCore.QLocale(QtCore.QLocale.Chinese, QtCore.QLocale.HongKong))
self.label = QtWidgets.QLabel(loginForm)
self.label.setGeometry(QtCore.QRect(180, 100, 54, 21))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(loginForm)
self.label_2.setGeometry(QtCore.QRect(180, 170, 54, 21))
self.label_2.setObjectName("label_2")
self.pushButton = QtWidgets.QPushButton(loginForm)
self.pushButton.setGeometry(QtCore.QRect(240, 250, 91, 31))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(loginForm)
self.pushButton_2.setGeometry(QtCore.QRect(350, 250, 91, 31))
self.pushButton_2.setObjectName("pushButton_2")
self.lineEdit = QtWidgets.QLineEdit(loginForm)
self.lineEdit.setGeometry(QtCore.QRect(240, 160, 201, 41))
self.lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(loginForm)
self.lineEdit_2.setGeometry(QtCore.QRect(240, 90, 201, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
self.retranslateUi(loginForm)
QtCore.QMetaObject.connectSlotsByName(loginForm)
def retranslateUi(self, loginForm):
_translate = QtCore.QCoreApplication.translate
loginForm.setWindowTitle(_translate("loginForm", "登录"))
self.label.setText(_translate("loginForm", "用户名"))
self.label_2.setText(_translate("loginForm", "密 码"))
self.pushButton.setText(_translate("loginForm", "登录"))
self.pushButton_2.setText(_translate("loginForm", "清除"))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = loginForm()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。