当我运行此代码并按下“预览条形码”按钮时,出现以下错误:
self.input_1.toPlainText() AttributeError:'MyWindowClass'对象没有属性'input_1'
为什么我收到此错误?
import sys
from PyQt4 import QtCore, QtGui, uic
_fromUtf8 = QtCore.QString.fromUtf8
class MyWindowClass(QtGui.QMainWindow):
def __init__(self):
super(MyWindowClass, self).__init__()
self.setupUi()
def setupUi(self):
self.setObjectName(_fromUtf8("Form"))
self.resize(559, 340)
previewButton = QtGui.QPushButton(self)
previewButton.setText(QtGui.QApplication.translate("form","Preview\nBarcode", None))
previewButton.setGeometry(QtCore.QRect(140, 20, 151, 101))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
previewButton.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Papyrus"))
font.setPointSize(18)
font.setBold(True)
font.setWeight(75)
previewButton.setFont(font)
previewButton.setObjectName(_fromUtf8("previewButton"))
input_1 = QtGui.QPlainTextEdit(self)
input_1.setFocus()
input_1.setGeometry(QtCore.QRect(10, 10, 104, 31))
input_1.setObjectName(_fromUtf8("input_1"))
previewButton.clicked.connect(self.previewButton_clicked)
input_1.cursorPositionChanged.connect(input_1.selectAll)
self.setWindowTitle('Barcode Generator')
self.show()
def previewButton_clicked(self):
self.input_1.toPlainText()
sum = 0.0
if float(addend1) > 0:
sum = sum + addend1
strSum = str('%.3f' % sum)
print(strSum)
def main():
app = QtGui.QApplication(sys.argv)
Form = MyWindowClass()
sys.exit(app.exec_())
if __name__ == '__main__':
main()