QPushButton
lightsBtn
是一个开关按钮,用于开关灯。当用户按下lightsBtn
时,函数lightsBtnHandler
将检查按钮当前是否被选中,并调用turnOnLights
或{
我认为self.sender()
能够访问QPushButton
的属性,但是我找不到任何关于访问选中状态的文档。在
有可能吗?在
class Screen(QMainWindow):
def initUI(self):
lightsBtn= QPushButton('Turn On')
lightsBtn.setCheckable(True)
lightsBtn.setStyleSheet("QPushButton:checked {color: white; background-color: green;}")
lightsBtn.clicked.connect(self.lightsBtnHandler)
lightsBtn.show()
def lightsBtnHandler(self):
if self.sender().?? isChecked(): # How to check for checked state?
self.turnOnLights()
else:
self.turnOffLights()
在@Matho注释之后,我对您的代码进行了一点修改。在
相关问题 更多 >
编程相关推荐