Convert Figma logo to code with AI

PyQt5 logoPyQt

PyQt Examples(PyQt各种测试和例子) PyQt4 PyQt5

6,736
1,977
6,736
4

Top Related Projects

17,941

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

2,346

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.

A Python module for creating Excel XLSX files.

Fast data visualization and GUI tools for scientific / engineering applications

matplotlib: plotting with Python

Quick Overview

PyQt5 is a comprehensive set of Python bindings for Qt v5, a popular cross-platform application framework. It allows developers to create desktop applications with Python that have a native look and feel on different operating systems, including Windows, macOS, and Linux.

Pros

  • Cross-platform compatibility, allowing developers to write once and deploy on multiple operating systems
  • Rich set of UI elements and widgets for creating complex, feature-rich applications
  • Extensive documentation and community support
  • Integration with Qt Designer for visual UI design

Cons

  • Steep learning curve for beginners, especially those new to GUI programming
  • Large package size, which can increase application deployment complexity
  • Licensing considerations (GPL or commercial license required for some use cases)
  • Performance can be slower compared to native C++ Qt applications

Code Examples

  1. Creating a simple window:
import sys
from PyQt5.QtWidgets import QApplication, QWidget

app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle('Simple PyQt5 Window')
window.setGeometry(100, 100, 300, 200)
window.show()
sys.exit(app.exec_())
  1. Adding a button with a click event:
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import pyqtSlot

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('PyQt5 Button Example')
        button = QPushButton('Click me', self)
        button.setToolTip('This is a button')
        button.move(100, 70)
        button.clicked.connect(self.on_click)
        self.show()

    @pyqtSlot()
    def on_click(self):
        print('Button clicked!')

app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
  1. Creating a simple form layout:
from PyQt5.QtWidgets import QApplication, QWidget, QFormLayout, QLineEdit, QLabel

class Form(QWidget):
    def __init__(self):
        super().__init__()
        layout = QFormLayout()
        layout.addRow(QLabel("Name:"), QLineEdit())
        layout.addRow(QLabel("Age:"), QLineEdit())
        layout.addRow(QLabel("Job:"), QLineEdit())
        self.setLayout(layout)
        self.setWindowTitle('Simple Form')

app = QApplication(sys.argv)
form = Form()
form.show()
sys.exit(app.exec_())

Getting Started

To get started with PyQt5:

  1. Install PyQt5 using pip:

    pip install PyQt5
    
  2. Import required modules in your Python script:

    from PyQt5.QtWidgets import QApplication, QWidget
    
  3. Create a QApplication instance and a main window:

    app = QApplication(sys.argv)
    window = QWidget()
    window.show()
    sys.exit(app.exec_())
    
  4. Run your script to see the basic PyQt5 application window.

Competitor Comparisons

17,941

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

Pros of Kivy

  • Cross-platform development for desktop, mobile, and web
  • Built-in touch support and gesture recognition
  • More flexible and customizable UI design with its own language (KV)

Cons of Kivy

  • Smaller community and fewer resources compared to PyQt
  • Steeper learning curve for beginners
  • Less native look and feel on desktop platforms

Code Comparison

Kivy:

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        return Button(text='Hello World')

MyApp().run()

PyQt:

import sys
from PyQt5.QtWidgets import QApplication, QPushButton

app = QApplication(sys.argv)
button = QPushButton('Hello World')
button.show()
sys.exit(app.exec_())

Both examples create a simple "Hello World" button application. Kivy's approach is more object-oriented and uses its own App class, while PyQt follows a more procedural style and relies on Qt's event loop.

Kivy is generally more suitable for multi-touch applications and cross-platform mobile development, while PyQt excels in creating desktop applications with a native look and feel. The choice between them depends on the specific requirements of your project and target platforms.

2,346

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.

Pros of Phoenix

  • Native look and feel across platforms
  • More permissive licensing (wxWidgets License)
  • Better support for legacy Windows systems

Cons of Phoenix

  • Smaller community and fewer resources compared to PyQt
  • Less comprehensive documentation
  • Slower development cycle and updates

Code Comparison

PyQt5:

from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication([])
label = QLabel("Hello World")
label.show()
app.exec_()

wxPython (Phoenix):

import wx
app = wx.App()
frame = wx.Frame(None, title="Hello World")
frame.Show()
app.MainLoop()

Both PyQt and Phoenix offer Python bindings for their respective GUI toolkits. PyQt is based on the Qt framework, while Phoenix is built on wxWidgets. PyQt has a larger community and more extensive documentation, making it easier for beginners. However, Phoenix offers a more native look and feel across different platforms and has a more permissive license, which can be advantageous for certain projects. PyQt generally has more frequent updates and a wider range of features, but Phoenix may be preferable for applications targeting older Windows systems or those requiring a truly native appearance.

A Python module for creating Excel XLSX files.

Pros of XlsxWriter

  • Specialized for Excel file creation, offering extensive Excel-specific features
  • Lightweight and focused, making it easier to learn and use for Excel tasks
  • Faster performance for large Excel file generation

Cons of XlsxWriter

  • Limited to Excel file manipulation, lacking GUI capabilities
  • Not suitable for general-purpose application development
  • Requires additional libraries for more complex data processing tasks

Code Comparison

XlsxWriter example:

import xlsxwriter

workbook = xlsxwriter.Workbook('example.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello, World!')
workbook.close()

PyQt example:

from PyQt5.QtWidgets import QApplication, QLabel

app = QApplication([])
label = QLabel('Hello, World!')
label.show()
app.exec_()

XlsxWriter is focused on creating Excel files with a straightforward API, while PyQt is a comprehensive GUI framework for building desktop applications. XlsxWriter excels in Excel-related tasks but lacks GUI capabilities, whereas PyQt offers extensive GUI functionality but requires more setup for simple tasks. The choice between them depends on the specific project requirements, whether it's Excel file manipulation or creating graphical user interfaces.

Fast data visualization and GUI tools for scientific / engineering applications

Pros of pyqtgraph

  • Specialized for scientific and engineering applications with fast-plotting capabilities
  • Extensive built-in widgets for data visualization and analysis
  • Simpler API for creating interactive plots and graphs

Cons of pyqtgraph

  • More limited in scope compared to PyQt's general-purpose GUI toolkit
  • Smaller community and fewer resources available
  • May require additional dependencies for certain functionalities

Code Comparison

PyQt5:

from PyQt5.QtWidgets import QApplication, QMainWindow
app = QApplication([])
window = QMainWindow()
window.show()
app.exec_()

pyqtgraph:

import pyqtgraph as pg
plt = pg.plot()
plt.plot([1, 2, 3, 4], [2, 4, 6, 8])
pg.exec()

PyQt5 provides a comprehensive framework for creating GUI applications, while pyqtgraph focuses on scientific plotting and data visualization. PyQt5 offers more flexibility for general-purpose applications, whereas pyqtgraph excels in creating interactive plots and graphs with less code. The choice between the two depends on the specific requirements of your project, with pyqtgraph being more suitable for scientific and engineering applications that require fast plotting capabilities.

matplotlib: plotting with Python

Pros of matplotlib

  • Specialized for creating static, animated, and interactive visualizations
  • Extensive documentation and large community support
  • Wide range of plot types and customization options

Cons of matplotlib

  • Steeper learning curve for complex visualizations
  • Less suitable for creating full GUI applications
  • Can be slower for real-time plotting of large datasets

Code Comparison

matplotlib:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.show()

PyQt5:

from PyQt5.QtWidgets import QApplication, QMainWindow
import sys

app = QApplication(sys.argv)
window = QMainWindow()
window.show()
sys.exit(app.exec_())

Summary

matplotlib excels in creating various types of plots and visualizations, while PyQt5 is better suited for developing full-fledged GUI applications. matplotlib offers a wide range of plotting options but may have a steeper learning curve for complex visualizations. PyQt5 provides more flexibility for creating interactive applications but requires more code for basic plotting tasks. The choice between the two depends on the specific requirements of your project, whether it's focused on data visualization or building a complete GUI application.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

各种各样的PyQt测试和例子

Blog codebeat badge Badge LICENSE

https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分享大家平时学习中记录的笔记和例子,以及对遇到的问题进行收集整理。

GitHub watchers GitHub stars GitHub forks

如果您觉得这里的东西对您有帮助,别忘了帮忙点一颗:star:小星星:star:

客户端下载 | 自定义控件

QQ群

or

       PyQt 学习                 PyQt 频道

状态

Alt

目录

其它项目

一些Qt写的三方APP

Donate-打赏

感谢所有捐助者的鼓励,这里 列出了捐助者名单(由于一些收款渠道无法知道对方是谁,如有遗漏请联系我修改)

or