Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yjg30737/pyqt-switch
PyQt Switch (O ) -> ( O)
https://github.com/yjg30737/pyqt-switch
pyqt pyqt-examples pyqt-gui pyqt-tutorial pyqt5 pyqt5-examples pyqt5-gui pyqt5-tutorial pyqtsignal python python3 python37 qpushbutton qt switchbutton
Last synced: 29 days ago
JSON representation
PyQt Switch (O ) -> ( O)
- Host: GitHub
- URL: https://github.com/yjg30737/pyqt-switch
- Owner: yjg30737
- License: mit
- Created: 2022-01-14T05:03:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-25T02:47:58.000Z (about 2 months ago)
- Last Synced: 2024-10-11T09:21:32.914Z (about 1 month ago)
- Topics: pyqt, pyqt-examples, pyqt-gui, pyqt-tutorial, pyqt5, pyqt5-examples, pyqt5-gui, pyqt5-tutorial, pyqtsignal, python, python3, python37, qpushbutton, qt, switchbutton
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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).
* `setChecked(bool)` - Toggle the switch programmatically
* `isChecked()` - Check switch is turned on## Example
Code Sample
```python
from PyQt5.QtWidgets import QWidget, QFormLayout, QApplication, QLabel
from pyqt_switch import PyQtSwitchclass Widget(QWidget):
def __init__(self):
super().__init__()
self.__initUi()def __initUi(self):
self.__label = QLabel()
self.__label.setText('No')switch = PyQtSwitch()
switch.toggled.connect(self.__toggled)
switch.setAnimation(True)
# switch.setChecked(True)
# switch.setCircleDiameter(40)# if switch.isChecked():
# print('Yes')
# else:
# print('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 sysapp = 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](https://user-images.githubusercontent.com/55078043/169002295-8717adf8-a1e6-4126-8ef9-42ff8bb3988c.png)