0
무엇이 잘못되었는지 알 수 없습니다. 레이블 텍스트를 '기본 레이블'에서 '새 레이블 01'로 변경하면됩니다. PySide.QtGui 가져 오기 *에서 이PySide에서 버튼을 눌러 레이블을 변경하는 방법
class myWidget(QWidget):
def __init__(self):
super(myWidget, self).__init__()
layout = QVBoxLayout(self)
label1 = QLabel('Default label')
layout.addWidget(label1)
button = QPushButton('Change')
layout.addWidget(button)
button.clicked.connect(self.newlabel)
def newlabel(self):
print 'ACTION1'
self.label1.setText('New label 01')
print 'ACTION2'
app = QApplication([])
window = myWidget()
window.show()
app.exec_()
이 내가 pycharm에서 실행 한 후 가지고 무엇
C:\Python27\python.exe D:/OneDrive/Projects/Personal/Tutorials/Python/CGScripting/PySide/simpleWidget.py
ACTION1
Traceback (most recent call last):
File "D:/OneDrive/Projects/Personal/Tutorials/Python/CGScripting/PySide/simpleWidget.py", line 32, in newlabel
self.label1.setText('New label 01')
AttributeError: 'myWidget' object has no attribute 'label1'
Process finished with exit code 0
예. 완벽하게 작동합니다. 고맙습니다. – user1682929