-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10. QRadioButton.py
59 lines (42 loc) · 1.69 KB
/
10. QRadioButton.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
51
52
53
54
55
56
57
58
59
from PyQt6.QtWidgets import QApplication, QWidget, QRadioButton,QVBoxLayout, QHBoxLayout, QLabel
from PyQt6.QtGui import QIcon
from PyQt6.QtCore import QSize # used for resize the icon size
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(200,200, 300,200)
self.setWindowTitle("PyQt6 QRadioButton")
self.setWindowIcon(QIcon('../images/python.png'))
self.create_radio()
def create_radio(self):
hbox = QHBoxLayout()
vbox = QVBoxLayout()
rad1 = QRadioButton("JavaScript")
rad1.setIcon(QIcon("../images/javascript.png"))
rad1.setIconSize(QSize(20,20)) # resize the icon size
rad1.setChecked(True) # for by-deafult checked
rad1.toggled.connect(self.radio_selected)
hbox.addWidget(rad1)
rad2 = QRadioButton("Python")
rad2.setIcon(QIcon("../images/python.png"))
rad2.setIconSize(QSize(20,20)) # resize the icon size
rad2.toggled.connect(self.radio_selected)
hbox.addWidget(rad2)
rad3 = QRadioButton("Java")
rad3.setIcon(QIcon("../images/java.png"))
rad3.setIconSize(QSize(20,20)) # resize the icon size
rad3.toggled.connect(self.radio_selected)
hbox.addWidget(rad3)
self.label = QLabel("")
vbox.addWidget(self.label)
vbox.addLayout(hbox)
self.setLayout(vbox)
def radio_selected(self):
radio_btn = self.sender()
if radio_btn.isChecked():
self.label.setText("You have selected: {}".format(radio_btn.text()))
app = QApplication(sys.argv)
Window = Window()
Window.show()
sys.exit(app.exec())