AttributeError: 'Ui_Dialog' object has no attribute 'lineEdit_3'
AttributeError: 'Ui_Dialog' object has no attribute 'lineEdit_3'
Link 到我的完整代码:https://www.dropbox.com/s/0tdnm2yd8038fwh/additem.py?dl=0
这是我得到的错误:
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 187, in <module>
ui = Ui_Dialog()
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 23, in __init__
self.setupUi(self)
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 66, in setupUi
self.buttonBox.accepted.connect(self.accept())
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 169, in accept
brandName = self.lineEdit_3.text()
AttributeError: 'Ui_Dialog' object has no attribute 'lineEdit_3'
在我补充之前一切顺利:
self.buttonBox.accepted.connect(self.accept())
调用此方法:
def accept(self):
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
unix = time.time()
dateUpdated = datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S')
company = self.lineEdit_2.text()
brandName = self.lineEdit_3.text()
genericName = self.lineEdit_4.text()
purchasePrice = self.lineEdit_5.text()
category = self.lineEdit_6.text()
sellingPrice = purchasePrice * sellingFactor
quantity = self.lineEdit_7.text()
#dosageForm = self.lineEdit_9.text()
expiryDate = self.lineEdit_10.text()
c.execute(
"INSERT INTO inventory(dateUpdated, company, brandName, genericName, category, purchasePrice, sellingPrice, quantity, expiryDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
(dateUpdated, company, brandName, genericName, category, purchasePrice, sellingPrice, quantity, expiryDate))
conn.commit()
这是剩余的代码:
app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
当你将一个信号连接到一个插槽时,你必须代表插槽传递它,语法如下
sender.signal.connect(receiver.slot)
在您的情况下,您必须更改:
self.buttonBox.accepted.connect(self.accept())
至:
self.buttonBox.accepted.connect(self.accept)
注意:当你传递PyQt槽名时你可以调用它,但如果你传递评估函数它就不可能这样做。
Link 到我的完整代码:https://www.dropbox.com/s/0tdnm2yd8038fwh/additem.py?dl=0
这是我得到的错误:
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 187, in <module>
ui = Ui_Dialog()
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 23, in __init__
self.setupUi(self)
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 66, in setupUi
self.buttonBox.accepted.connect(self.accept())
File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 169, in accept
brandName = self.lineEdit_3.text()
AttributeError: 'Ui_Dialog' object has no attribute 'lineEdit_3'
在我补充之前一切顺利:
self.buttonBox.accepted.connect(self.accept())
调用此方法:
def accept(self):
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
unix = time.time()
dateUpdated = datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S')
company = self.lineEdit_2.text()
brandName = self.lineEdit_3.text()
genericName = self.lineEdit_4.text()
purchasePrice = self.lineEdit_5.text()
category = self.lineEdit_6.text()
sellingPrice = purchasePrice * sellingFactor
quantity = self.lineEdit_7.text()
#dosageForm = self.lineEdit_9.text()
expiryDate = self.lineEdit_10.text()
c.execute(
"INSERT INTO inventory(dateUpdated, company, brandName, genericName, category, purchasePrice, sellingPrice, quantity, expiryDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
(dateUpdated, company, brandName, genericName, category, purchasePrice, sellingPrice, quantity, expiryDate))
conn.commit()
这是剩余的代码:
app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
当你将一个信号连接到一个插槽时,你必须代表插槽传递它,语法如下
sender.signal.connect(receiver.slot)
在您的情况下,您必须更改:
self.buttonBox.accepted.connect(self.accept())
至:
self.buttonBox.accepted.connect(self.accept)
注意:当你传递PyQt槽名时你可以调用它,但如果你传递评估函数它就不可能这样做。