title: How to assign a value to a radiobutton in pyqt?
body: <p>I want to assign a value to a radiobutton when it is checked. </p>
  
  <pre class="lang-py prettyprint-override"><code>def radiobutton8(self):
      if self.radioButton_8.isChecked():
          self.radioButton_8 = 02
  </code></pre>
  
  <p>However, this cannot work. Any solution?</p>
  
  <p>UPDATE: My code has been edited to be:</p>
  
  <pre class="lang-py prettyprint-override"><code>class MyRadioButton(QtGui.QRadioButton):
      def __init__(self):
          super(MyRadioButton, self).__init__()
          self.value = None
  
      def SetValue(self, val):
          self.value = val
  
      def GetValue(self):
          return self.value
  
  class UserTool(QtGui.QDialog):
      def setup(self, Dialog):
                            ...
          self.radioButton_8.toggled.connect(self.radiobutton8)
  
      def retranslateUi(self, Dialog):
                            ...
          self.radioButton_8 = MyRadioButton()
          self.radioButton_8.setText(_translate("Dialog", "A1", None))
  
  def radiobutton8(self):
      if self.radioButton_8.isChecked():
          value = self.radioButton_8.setValue("02")
          self.lcdNumber.display(value)
  </code></pre>
  
  <p>However, my original text 'A1' for the radio button is now missing and my number still does not appear on my lcd when checked. Any idea why?</p>
  
  <p>UPDATE: I edited my code to  be something like that:</p>
  
  <pre class="lang-py prettyprint-override"><code>class MyRadioButton(QtGui.QRadioButton):
      def __init__(self):
          super(MyRadioButton, self).__init__()
          self.value = None
  
      def SetValue(self, val):
          self.value = val
  
      def GetValue(self):
          return self.value
  
  class UserTool(QtGui.QDialog):
      def setup(self, Dialog):
                    ...
          self.lcdNumber = QtGui.QLCDNumber(Dialog)
          self.lcdNumber.setGeometry(QtCore.QRect(590, 10, 71, 23))
          self.lcdNumber.setFrameShadow(QtGui.QFrame.Raised)
          self.lcdNumber.setObjectName(_fromUtf8("lcdNumber"))
          self.lcdNumber.setStyleSheet("* {background-color: black; color: white;}")
          self.lcdNumber.display('00')
  
          self.radioButton_8 = QtGui.QRadioButton(Dialog)
          self.radioButton_8.setGeometry(QtCore.QRect(460, 10, 82, 17))
          self.radioButton_8.setChecked(False)
          self.radioButton_8.setAutoExclusive(False)
          self.radioButton_8.setObjectName(_fromUtf8("radioButton_8")) 
          self.radioButton_8 = MyRadioButton()
          self.radioButton_8.setText("A1")
          self.radioButton_8.setValue(02)
          self.radioButton_8.toggled.connect(self.showValueFromRadioButtonToLCDNumber)
  
      def showValueFromRadioButtonToLCDNumber(self):
          value = self.radioButton_8.GetValue()
          if self.radioButton_8.isChecked():
              self.lcdNumber.display(value)
  </code></pre>
  
  <p>And then now I have this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/Vivien Phua/Documents/Python Scripts/Rs232.py", line 303, in handleOpenWidget
      self.popup = UserTool()
    File "C:/Users/Vivien Phua/Documents/Python Scripts/Rs232.py", line 39, in __init__
      self.setup(self)
    File "C:/Users/Vivien Phua/Documents/Python Scripts/Rs232.py", line 153, in setup
      self.radioButton_8.setValue(02)
  AttributeError: 'MyRadioButton' object has no attribute 'setValue'
  </code></pre>
  
  <p>I have also tried the code you have given me and there is no such error, but the LCD in your code does not show the value 02.</p>