Try it:
import sys
from PyQt5.QtWidgets import (QLabel, QRadioButton, QPushButton, QVBoxLayout, QApplication, QWidget)
class Window(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.lbl = QLabel('Which do you like ?')
self.rb1 = QRadioButton('PyQt4')
self.rb2 = QRadioButton('PyQt5')
self.rb2.setChecked(True)
self.btn = QPushButton('Select')
layout = QVBoxLayout()
layout.addWidget(self.lbl)
layout.addWidget(self.rb1)
layout.addWidget(self.rb2)
layout.addWidget(self.btn)
self.setLayout(layout)
self.setWindowTitle('PyQt5 QRadioButton')
self.btn.clicked.connect(lambda: self.btn_clk(self.rb1.isChecked(), self.lbl))
def btn_clk(self, chk, lbl):
if chk:
lbl.setText('It1s time to switch to PyQt5.')
self.A('It1s time to switch to PyQt5.')
else:
lbl.setText('It`s a great choice!')
self.B('It`s a great choice!')
def A(self, text):
print(text)
def B(self, text):
print(text)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
