Skip to main content

PyQt Switch (O ) -> ( O)

Project description

pyqt-switch

PyQt Switch (O ) -> ( O)

You can choose the option to set the colorizing/moving animation.

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-switch

Feature

  • Provide toggled(bool) signal

  • Set the animation with setAnimation(f: bool). Default is False.

  • Set the diameter of circle-shaped switch button with setCircleDiameter(diameter: int). Default is 20(px).

Example

Code Sample

from PyQt5.QtWidgets import QWidget, QFormLayout, QApplication, QLabel

from pyqt_switch import PyQtSwitch





class Widget(QWidget):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        switch = PyQtSwitch()

        switch.toggled.connect(self.__toggled)

        switch.setAnimation(True)

        # switch.setCircleDiameter(40)



        self.__label = QLabel()

        self.__label.setText('No')

        lay = QFormLayout()

        lay.addRow(self.__label, switch)

        self.setLayout(lay)



    def __toggled(self, f):

        if f:

            self.__label.setText('Yes')

        else:

            self.__label.setText('No')





if __name__ == "__main__":

    import sys



    app = QApplication(sys.argv)

    example = Widget()

    example.show()

    app.exec_()

Result

https://user-images.githubusercontent.com/55078043/169001914-0b86407a-5670-4ae4-ac28-54ec85460bc0.mp4

If you set the circle diameter to 40 with switch.setCircleDiameter(40)

image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt-switch-0.0.16.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

pyqt_switch-0.0.16-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page