-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyQt5_QCheckBoxWidget.py
50 lines (35 loc) · 1.16 KB
/
PyQt5_QCheckBoxWidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class checkdemo(QWidget):
def __init__(self, parent=None):
super(checkdemo, self).__init__(parent)
layout = QHBoxLayout()
self.b1 = QCheckBox("Button1")
self.b1.setChecked(True)
self.b1.stateChanged.connect(lambda: self.btnstate(self.b1))
layout.addWidget(self.b1)
self.b2 = QCheckBox("Button2")
self.b2.toggled.connect(lambda: self.btnstate(self.b2))
layout.addWidget(self.b2)
self.setLayout(layout)
self.setWindowTitle("checkbox demo")
def btnstate(self, b):
if b.text() == "Button1":
if b.isChecked() == True:
print(b.text() + " is selected")
else:
print(b.text() + " is deselected")
if b.text() == "Button2":
if b.isChecked() == True:
print(b.text() + " is selected")
else:
print(b.text() + " is deselected")
def main():
app = QApplication(sys.argv)
ex = checkdemo()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()