Advertisement
cpfluger

Untitled

Dec 8th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. from PyQt5.QtWidgets import QRadioButton, QApplication, QVBoxLayout, QWidget
  2.  
  3. def onClicked(button):
  4.     if button.text() == 'Button1':
  5.         if button.isChecked():
  6.             print("Button1 is checked")
  7.     if button.text() == 'Button2':
  8.         if button.isChecked():
  9.             print("Button2 is checked")
  10.  
  11. app = QApplication([])
  12. window = QWidget()
  13.  
  14. RadioButton1 = QRadioButton('Button1')
  15. RadioButton2 = QRadioButton('Button2')
  16.  
  17. RadioButton1.toggled.connect(lambda:onClicked(RadioButton1))
  18. RadioButton2.toggled.connect(lambda:onClicked(RadioButton2))
  19.  
  20. layout = QVBoxLayout()
  21. layout.addWidget(RadioButton1)
  22. layout.addWidget(RadioButton2)
  23.  
  24. window.setLayout(layout)
  25. window.setGeometry(200, 200, 300, 150)
  26. window.setWindowTitle('RadioButton Example')
  27. window.show()
  28. app.exec_()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement