라디오 버튼을 선택했을 때 값을 지정하고 싶습니다.pyqt의 라디오 버튼에 값을 지정하는 방법은 무엇입니까?
def radiobutton8(self):
if self.radioButton_8.isChecked():
self.radioButton_8 = 02
그러나 이것은 작동하지 않습니다. 어떤 해결책?
은 UPDATE : 내 코드로 편집 한 :
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)
그러나, 라디오 버튼에 대한 내 원래의 텍스트 'A1'은 이제없는 및 검사 때 내 번호는 여전히 내 LCD에 표시되지 않습니다. 왜 그런가?
업데이트 : 그런 뭔가 내 코드를 편집 :
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)
을 그리고 지금은이 오류가 : 나는 또한 당신이 나에게 주어지고있는 코드를 시도
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'
을 그런 오류는 없지만 코드의 LCD에 값 02가 표시되지 않습니다.
은 : setValue의하지 SetValue는 될 것으로 생각된다. 코드 당신이 그것을 보여주기를 원하면 코드 2를 보여 주겠다. 02 : 그 값을'self.radioButton_8.SetValue (02)'대신에'self.radioButton_8.SetValue ("02")'문자열로 설정하라. 내가 EDIT2에서 내 대답에 업데이 트했습니다,하지만 당신은 내가 EDIT1에서 언급 한 적이 있다면 – Aleksandar
EDIT2에서 코드를 실행하려고 시도하고 그것이 self.radioButton.SetValue ("02")인지 확인했지만 여전히 작동하지 않습니다. 라디오 버튼을 선택하면 아무 반응이 없습니다. – Viv91
오! 나는이 줄'self.pushButton_7.clicked.connect (self.showValueFromRadioButtonToLCDNumber)'를 삭제하고'self.radioButton.toggled.connect (self.showValueFromRadioButtonToLCDNumber)'를 추가했다. 그러나 라디오 버튼을 선택하지 않은 상태에서 체크 표시를 해제하면 LCD 디스플레이를 되돌릴 수 있습니까? – Viv91