Skip to main content

PyQt Loading Button

PyPI Python License Coverage Build

A QPushButton with built-in loading animations for PyQt and PySide.

Main

About

The widget functions exactly like PyQt's regular QPushButton with the only exception being the way methods are connected to the clicked event. Normally you would connect a method to the clicked event by using the connect() method. On this button you use the setAction() method instead, passing a callable object as its parameter the same way you would do with the connect() method. The method will then get executed in a QThread, allowing the button to display a loading animation.

Installation

pip install pyqt-loading-button

Example

import time
from PyQt6.QtGui import QColor
from PyQt6.QtWidgets import QMainWindow
from pyqt_loading_button import LoadingButton, AnimationType


class Window(QMainWindow):

    def __init__(self):
        super().__init__(parent=None)

        # LoadingButton
        self.button_1 = LoadingButton(self)
        self.button_1.setText('Click me!')
        self.button_1.setAnimationType(AnimationType.Circle)
        self.button_1.setAnimationSpeed(2000)
        self.button_1.setAnimationColor(QColor(0, 0, 0))
        self.button_1.setAnimationWidth(15)
        self.button_1.setAnimationStrokeWidth(3)
        self.button_1.setAction(self.do_something)

    def do_something(self):
        time.sleep(5)  # Simulate long task

Documentation

  • Setting the button text:
loading_button.setText('Click me!')
  • Setting the action connected to the clicked event:
def do_something():
    time.sleep(5)  # Simulate long task

loading_button.setAction(do_something)
  • Setting the animation type:
loading_button.setAnimationType(AnimationType.Circle)  # Circular animation
loading_button.setAnimationType(AnimationType.Dots)    # Dotted animation
  • Setting the animation speed:
# 2000 means each loop of the animation takes 2000 ms to complete
loading_button.setAnimationSpeed(2000)
  • Setting the animation width:
loading_button.setAnimationWidth(15)  # Total width of the animation is 15 px
  • Setting the animation stroke width:
loading_button.setAnimationStrokeWidth(3)  # Stroke width of the brush is 3 px
  • Setting the animation color:
loading_button.setAnimationColor(QColor(0, 0, 0))
  • Checking whether the action is currently being executed:
loading_button.isRunning()


All methods:

Method Description
text(self) Get the current button text
setText(self, text: str) Set the button text
setAction(self, action: callable) Set the action connected to the clicked event
isRunning(self) Get whether the action is currently being executed
getAnimationType(self) Get the current animation type
setAnimationType(self, animation_type: AnimationType) Set the animation type
getAnimationSpeed(self) Get the current animation speed (time it takes the animation to complete one loop in ms)
setAnimationSpeed(self, speed: int) Set the animation speed (time it takes the animation to complete one loop in ms)
getAnimationWidth(self) Get the current width of the animation
setAnimationWidth(self, width: int) Set the width of the animation
getAnimationStrokeWidth(self) Get the current width of the brush stroke
setAnimationStrokeWidth(self, width: int) Set the width of the brush stroke
getAnimationColor(self) Get the current animation color
setAnimationColor(self, color: QColor) Set the animation color

License

This software is licensed under the MIT license.

Metadata

Release files for pyqt-loading-button 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyqt-loading-button 1.0.0
File Size Uploaded
pyqt-loading-button-1.0.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyqt-loading-button 1.0.0
File Interpreter ABI Platform
pyqt_loading_button-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / pyqt-loading-button-1.0.0.tar.gz

Download URL pyqt-loading-button-1.0.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b9ab3428c482e65915c38369e9ed9028ea4dead4977ef729bb24402d01f79de9
BLAKE2b-256 checksum
How to use checksums
5c09e79f4bbc0f40ee790a773dcbaf783cfafd2e6db16421993713112728cd89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release files / pyqt_loading_button-1.0.0-py3-none-any.whl

Download URL pyqt_loading_button-1.0.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
423abef5e286fa818d61f10298716a9559f0cc36dc38397e9eac85cc4bc33cb6
BLAKE2b-256 checksum
How to use checksums
4a09774de44140238399e4e39c573cf7322a8b8931e08ee949b60353a373baba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page