[Python] 如何在windows10下搭建pyqt6环境

关于pyqt6

Qt库是最强大的GUI库之一。PyQt6是由Riverbank Computing公司开发的。

PyQt6 是基于 Python 的一系列模块。它是一个多平台的工具包,可以在包括Unix、Windows和Mac OS在内的大部分主要操作系统上运行。PyQt6 有两个许可证,开发人员可以在 GPL 和商业许可之间进行选择。

PyQt6的官网:http://www.riverbankcomputing.co.uk/news。

Reference Guide — PyQt Documentation v6.6.0 (riverbankcomputing.com)

Introduction¶

This is the reference guide for PyQt6 v6.6. PyQt6 is a set of Python bindings for v6 of the Qt application framework from The Qt Company.

Qt is a set of C++ libraries and development tools that includes platform independent abstractions for graphical user interfaces, networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, user and application settings, positioning and location services, short range communications (NFC and Bluetooth), web browsing, 3D animation, charts, 3D data visualisation and interfacing with app stores.

PyQt6 comprises PyQt6 itself and a number of add-ons that correspond to Qt’s additional libraries. At the moment these are PyQt6-3D and PyQt6-NetworkAuth. Each is provided as a source distribution (sdist) and binary wheels for Windows, Linux and macOS.

PyQt6 supports the Windows, Linux, Android, macOS and iOS platforms and requires Python v3.6.1 or later.

The homepage for PyQt6 is Riverbank Computing | Introduction. Here you will always find the latest stable version and current development snapshots.

通过conda创建虚拟环境

conda create -y -n yolo_tools_310 python=3.10

如何安装和使用conda,可以阅读:[Python] conda、anaconda、miniconda的关系,miniconda安装,conda命令使用

激活虚拟环境

conda activate yolo_tools_310

通过pip来安装pyqt6

pip install pyqt6

验证pyqt6安装成功

第一个pyqt6应用程序

from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget
import sys


def center_window(window:QWidget):
    q_rect = window.frameGeometry()  # 得到一个指定主窗口几何形状的矩形
    cp = window.screen().availableGeometry().center()  # 计算出显示器的分辨率,通过分辨率得出中心点
    q_rect.moveCenter(cp)  # 设置为屏幕的中心,矩形大小不变
    window.move(q_rect.topLeft())


app = QApplication(sys.argv)
window = QMainWindow()
window.setWindowTitle("Yolo工具箱")
window.setGeometry(0, 0, 800, 600)
window.statusBar().showMessage("欢迎来到Yolo工具箱")
window.menuBar().addMenu("训练管理")
center_window(window)
window.showMaximized()

sys.exit(app.exec())

[Python] 如何在windows10下搭建pyqt6环境_第1张图片

你可能感兴趣的:(python,python,pyqt6)