36 lines
1016 B
Python
36 lines
1016 B
Python
from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QLabel, QWidget
|
|
from switch_button import SwitchButton
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
self.setWindowTitle("Switch Button Example")
|
|
self.setGeometry(100, 100, 200, 100)
|
|
|
|
# 创建 SwitchButton 和状态标签
|
|
self.switch = SwitchButton(width=30, height=10)
|
|
self.status_label = QLabel("Off")
|
|
|
|
# 绑定开关事件
|
|
self.switch.clicked.connect(self.on_switch_toggled)
|
|
|
|
# 布局
|
|
layout = QVBoxLayout()
|
|
layout.addWidget(self.switch)
|
|
layout.addWidget(self.status_label)
|
|
|
|
central_widget = QWidget()
|
|
central_widget.setLayout(layout)
|
|
self.setCentralWidget(central_widget)
|
|
|
|
def on_switch_toggled(self, checked):
|
|
self.status_label.setText("On" if checked else "Off")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication([])
|
|
window = MainWindow()
|
|
window.show()
|
|
app.exec()
|