PyQt5说明
pyqt5是一套Python绑定Digia QT5应用的框架。它可用于Python 2和3。本教程使用Python 3。Qt库是最强大的GUI库之一。pyqt5的官方网站http://www.riverbankcomputing.co.uk/news。
pyqt5做为Python的一个模块,它有620多个类和6000个函数和方法。这是一个跨平台的工具包,它可以运行在所有主要的操作系统,包括UNIX,Windows,Mac OS。pyqt5是双重许可。开发者可以在GPL和商业许可之间进行选择。
pyqt5的类别分为几个模块,包括以下:
- QtCore:包含了核心的非GUI功能。此模块用于处理时间、文件和目录、各种数据类型、流、URL、MIME类型、线程或进程。
- QtGui:包含类窗口系统集成、事件处理、二维图形、基本成像、字体和文本。
- QtWidgets:包含创造经典桌面风格的用户界面提供了一套UI元素的类。
- QtMultimedia:包含的类来处理多媒体内容和API来访问相机和收音机的功能。
- QtBluetooth:包含类的扫描设备和连接并与他们互动。描述模块包含了网络编程的类。这些类便于TCP和IP和UDP客户端和服务器的编码,使网络编程更容易和更便携。
- QtNetwork
- QtPositioning:包含类的利用各种可能的来源,确定位置,包括卫星、Wi-Fi、或一个文本文件。
- Enginio:模块实现了客户端库访问Qt云服务托管的应用程序运行时。
- QtWebSockets:包含实现WebSocket协议类。
- QtWebKit:包含一个基于Webkit2图书馆Web浏览器实现类。
- QtWebKitWidgets:包含的类的基础webkit1一用于qtwidgets应用Web浏览器的实现。
- QtXml:包含与XML文件的类。这个模块为SAX和DOM API提供了实现。
- QtSvg:提供了显示SVG文件内容的类。可伸缩矢量图形(SVG)是一种描述二维图形和图形应用的语言。
- QtSql:提供操作数据库的类。
- QtTest:包含测试的功能,使pyqt5应用程序的单元测试
PyQt4和PyQt5的区别
pyqt5不向后兼容pyqt4。pyqt5有几个显著的变化。将旧代码调整到新库并不困难。有几个大的改变如下:
- Python模块已经重组。一些模块已经删除(qtscript),有的被分割成子模块(QtGui,QtWebKit)。
- 新的模块作了详细的介绍,包括qtbluetooth,qtpositioning,或enginio。
- pyqt5只支持新型的信号和槽handlig。电话signal()或slot()不再支持。
- pyqt5不支持Qt的API被标记为过时或陈旧的任何部分在QT V5.0。
Demo
本人曾写过一个数字货币搬砖的界面,效果如下图:
界面的设计用的是pyqt5,设计完成后使用命令 python -m PyQt5.uic.pyuic xxx.ui -o xxx.py 转换为python的代码
转换后的代码:
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file ‘test7.ui‘ # # Created by: PyQt5 UI code generator 5.11.2 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(753, 744) self.formLayoutWidget = QtWidgets.QWidget(Dialog) self.formLayoutWidget.setGeometry(QtCore.QRect(180, 30, 321, 411)) self.formLayoutWidget.setObjectName("formLayoutWidget") self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget) self.formLayout.setContentsMargins(0, 0, 0, 0) self.formLayout.setObjectName("formLayout") self.symbol_label = QtWidgets.QLabel(self.formLayoutWidget) self.symbol_label.setObjectName("symbol_label") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.symbol_label) self.symbol_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.symbol_LineEdit.setObjectName("symbol_LineEdit") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.symbol_LineEdit) self.amount_label = QtWidgets.QLabel(self.formLayoutWidget) self.amount_label.setObjectName("amount_label") self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.amount_label) self.amount_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.amount_LineEdit.setObjectName("amount_LineEdit") self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.amount_LineEdit) self.label_3 = QtWidgets.QLabel(self.formLayoutWidget) self.label_3.setText("") self.label_3.setObjectName("label_3") self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.label_3) self.rate_diff_label = QtWidgets.QLabel(self.formLayoutWidget) self.rate_diff_label.setObjectName("rate_diff_label") self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.rate_diff_label) self.rate_diff_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.rate_diff_LineEdit.setObjectName("rate_diff_LineEdit") self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.rate_diff_LineEdit) self.side_label = QtWidgets.QLabel(self.formLayoutWidget) self.side_label.setObjectName("side_label") self.formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.side_label) self.huobi_buy_gemini_sell = QtWidgets.QRadioButton(self.formLayoutWidget) self.huobi_buy_gemini_sell.setObjectName("huobi_buy_gemini_sell") self.formLayout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.huobi_buy_gemini_sell) self.binance_buy_gemini_sell = QtWidgets.QRadioButton(self.formLayoutWidget) self.binance_buy_gemini_sell.setObjectName("binance_buy_gemini_sell") self.formLayout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.binance_buy_gemini_sell) self.gemini_buy_huobi_sell = QtWidgets.QRadioButton(self.formLayoutWidget) self.gemini_buy_huobi_sell.setObjectName("gemini_buy_huobi_sell") self.formLayout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.gemini_buy_huobi_sell) self.gemini_buy_binance_sell = QtWidgets.QRadioButton(self.formLayoutWidget) self.gemini_buy_binance_sell.setObjectName("gemini_buy_binance_sell") self.formLayout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.gemini_buy_binance_sell) self.buy_ApiKey_label = QtWidgets.QLabel(self.formLayoutWidget) self.buy_ApiKey_label.setObjectName("buy_ApiKey_label") self.formLayout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.buy_ApiKey_label) self.buy_ApiKey_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.buy_ApiKey_LineEdit.setObjectName("buy_ApiKey_LineEdit") self.formLayout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.buy_ApiKey_LineEdit) self.buy_SecretKey_label = QtWidgets.QLabel(self.formLayoutWidget) self.buy_SecretKey_label.setObjectName("buy_SecretKey_label") self.formLayout.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.buy_SecretKey_label) self.buy_SecretKey_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.buy_SecretKey_LineEdit.setObjectName("buy_SecretKey_LineEdit") self.formLayout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.buy_SecretKey_LineEdit) self.sell_ApiKey_label = QtWidgets.QLabel(self.formLayoutWidget) self.sell_ApiKey_label.setObjectName("sell_ApiKey_label") self.formLayout.setWidget(13, QtWidgets.QFormLayout.LabelRole, self.sell_ApiKey_label) self.sell_ApiKey_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.sell_ApiKey_LineEdit.setObjectName("sell_ApiKey_LineEdit") self.formLayout.setWidget(13, QtWidgets.QFormLayout.FieldRole, self.sell_ApiKey_LineEdit) self.sell_Secretkey_label = QtWidgets.QLabel(self.formLayoutWidget) self.sell_Secretkey_label.setObjectName("sell_Secretkey_label") self.formLayout.setWidget(14, QtWidgets.QFormLayout.LabelRole, self.sell_Secretkey_label) self.sell_Secretkey_LineEdit = QtWidgets.QLineEdit(self.formLayoutWidget) self.sell_Secretkey_LineEdit.setObjectName("sell_Secretkey_LineEdit") self.formLayout.setWidget(14, QtWidgets.QFormLayout.FieldRole, self.sell_Secretkey_LineEdit) self.result_info = QtWidgets.QLabel(self.formLayoutWidget) self.result_info.setText("") self.result_info.setObjectName("result_info") self.formLayout.setWidget(15, QtWidgets.QFormLayout.SpanningRole, self.result_info) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(160, 10, 231, 19)) self.label.setObjectName("label") self.gemini_currency_label = QtWidgets.QLabel(Dialog) self.gemini_currency_label.setGeometry(QtCore.QRect(170, 580, 101, 20)) self.gemini_currency_label.setObjectName("gemini_currency_label") self.gemini_usd_label = QtWidgets.QLabel(Dialog) self.gemini_usd_label.setGeometry(QtCore.QRect(170, 610, 101, 20)) self.gemini_usd_label.setObjectName("gemini_usd_label") self.exchange_currency_label = QtWidgets.QLabel(Dialog) self.exchange_currency_label.setGeometry(QtCore.QRect(170, 640, 101, 20)) self.exchange_currency_label.setObjectName("exchange_currency_label") self.exchange_usd_label = QtWidgets.QLabel(Dialog) self.exchange_usd_label.setGeometry(QtCore.QRect(170, 670, 101, 20)) self.exchange_usd_label.setObjectName("exchange_usd_label") self.result_label = QtWidgets.QLabel(Dialog) self.result_label.setGeometry(QtCore.QRect(170, 470, 60, 16)) self.result_label.setObjectName("result_label") self.trade_per_label = QtWidgets.QLabel(Dialog) self.trade_per_label.setGeometry(QtCore.QRect(210, 550, 60, 16)) self.trade_per_label.setObjectName("trade_per_label") self.trade_per_text = QtWidgets.QTextBrowser(Dialog) self.trade_per_text.setGeometry(QtCore.QRect(280, 550, 121, 21)) self.trade_per_text.setObjectName("trade_per_text") self.gemini_currency_text = QtWidgets.QTextBrowser(Dialog) self.gemini_currency_text.setGeometry(QtCore.QRect(280, 580, 251, 21)) self.gemini_currency_text.setObjectName("gemini_currency_text") self.gemini_usd_text = QtWidgets.QTextBrowser(Dialog) self.gemini_usd_text.setGeometry(QtCore.QRect(280, 610, 251, 21)) self.gemini_usd_text.setObjectName("gemini_usd_text") self.exchange_currency_text = QtWidgets.QTextBrowser(Dialog) self.exchange_currency_text.setGeometry(QtCore.QRect(280, 640, 251, 21)) self.exchange_currency_text.setObjectName("exchange_currency_text") self.exchange_usd_text = QtWidgets.QTextBrowser(Dialog) self.exchange_usd_text.setGeometry(QtCore.QRect(280, 670, 251, 21)) self.exchange_usd_text.setObjectName("exchange_usd_text") self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(220, 440, 141, 32)) self.pushButton.setObjectName("pushButton") self.bid_price_label = QtWidgets.QLabel(Dialog) self.bid_price_label.setGeometry(QtCore.QRect(230, 490, 51, 20)) self.bid_price_label.setObjectName("bid_price_label") self.bid_price_text = QtWidgets.QTextBrowser(Dialog) self.bid_price_text.setGeometry(QtCore.QRect(280, 490, 121, 21)) self.bid_price_text.setObjectName("bid_price_text") self.ask_price_label = QtWidgets.QLabel(Dialog) self.ask_price_label.setGeometry(QtCore.QRect(230, 520, 51, 20)) self.ask_price_label.setObjectName("ask_price_label") self.ask_price_text = QtWidgets.QTextBrowser(Dialog) self.ask_price_text.setGeometry(QtCore.QRect(280, 520, 121, 21)) self.ask_price_text.setObjectName("ask_price_text") self.net_test_button = QtWidgets.QPushButton(Dialog) self.net_test_button.setGeometry(QtCore.QRect(40, 400, 113, 41)) self.net_test_button.setObjectName("net_test_button") self.stop_btn = QtWidgets.QPushButton(Dialog) self.stop_btn.setGeometry(QtCore.QRect(390, 440, 141, 32)) self.stop_btn.setObjectName("stop_btn") self.amount_ps_label_2 = QtWidgets.QLabel(Dialog) self.amount_ps_label_2.setGeometry(QtCore.QRect(420, 80, 228, 19)) self.amount_ps_label_2.setObjectName("amount_ps_label_2") self.amount_ps_label = QtWidgets.QLabel(Dialog) self.amount_ps_label.setGeometry(QtCore.QRect(420, 60, 264, 19)) self.amount_ps_label.setObjectName("amount_ps_label") self.symbol_ps_label = QtWidgets.QLabel(Dialog) self.symbol_ps_label.setGeometry(QtCore.QRect(420, 30, 168, 19)) self.symbol_ps_label.setObjectName("symbol_ps_label") self.rate_ps_label = QtWidgets.QLabel(Dialog) self.rate_ps_label.setGeometry(QtCore.QRect(420, 120, 214, 19)) self.rate_ps_label.setObjectName("rate_ps_label") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.symbol_label.setText(_translate("Dialog", "品种")) self.amount_label.setText(_translate("Dialog", "数量")) self.rate_diff_label.setText(_translate("Dialog", "利率差")) self.side_label.setText(_translate("Dialog", "买卖方向")) self.huobi_buy_gemini_sell.setText(_translate("Dialog", "huobi买,gemini卖")) self.binance_buy_gemini_sell.setText(_translate("Dialog", "binance买,gemini卖")) self.gemini_buy_huobi_sell.setText(_translate("Dialog", "gemini买,huobi卖")) self.gemini_buy_binance_sell.setText(_translate("Dialog", "gemini买,binance卖")) self.buy_ApiKey_label.setText(_translate("Dialog", "买_ApiKey")) self.buy_SecretKey_label.setText(_translate("Dialog", "买_SecretKey")) self.sell_ApiKey_label.setText(_translate("Dialog", "卖_ApiKey")) self.sell_Secretkey_label.setText(_translate("Dialog", "卖_Secret_key")) self.label.setText(_translate("Dialog", "输入参数")) self.gemini_currency_label.setText(_translate("Dialog", "gemini-品种余额")) self.gemini_usd_label.setText(_translate("Dialog", "gemini-usd余额")) self.exchange_currency_label.setText(_translate("Dialog", " 交易所-品种余额")) self.exchange_usd_label.setText(_translate("Dialog", "交易所-usdt余额")) self.result_label.setText(_translate("Dialog", "结果")) self.trade_per_label.setText(_translate("Dialog", "交易进度")) self.pushButton.setText(_translate("Dialog", "开始")) self.bid_price_label.setText(_translate("Dialog", "买一价")) self.ask_price_label.setText(_translate("Dialog", "卖一价")) self.net_test_button.setText(_translate("Dialog", "点击测试网络")) self.stop_btn.setText(_translate("Dialog", "停止")) self.amount_ps_label_2.setText(_translate("Dialog", " binance:10usdt交易额")) self.amount_ps_label.setText(_translate("Dialog", "注:最小交易量: huobi:eth--0.01,btc--0.001")) self.symbol_ps_label.setText(_translate("Dialog", "注:输入币种名(btc | eth)")) self.rate_ps_label.setText(_translate("Dialog", "注:输入小数,如0.18%即填0.18 "))
ui_demo
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff }
span.s1 { }
原文地址:https://www.cnblogs.com/zhuminghui/p/9507887.html
时间: 2024-10-12 04:50:33