I'm trying to run a simple PyQT4 application. I've installed Python3.4 and PyQt4. I've tested a simple "Hello World" app and all works well. However when trying to code a simple tax calculator app I'm getting stuck with a "unexpected type 'method'" error. Not sure what I'm doing wrong. Here's my python code:
import sys
from PyQt4 import QtCore, QtGui, uic
qtCreatorFile = 'tax.ui' # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.calcTax.connect(self.CalculateTax)
def CalculateTax(self):
price = int(self.priceBox.toPlainText())
tax = (self.taxRate.value())
total_price = price + ((tax / 100) * price)
total_price_string = 'The total price with tax is: ' + str(total_price)
self.resultBox.setText(total_price_string)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
and here's the full error message returned when executing:
Traceback (most recent call last):
File "tax.py", line 24, in <module>
window = tax()
File "tax.py", line 13, in __init__
self.calcTax.connect(self.CalculateTax)
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'method'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'method'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'method'
Would really appreciate any help
答案 0 :(得分:0)
new connection style具有以下语法:
self.calcTax.some_signal.connect(self.CalculateTax)
例如,如果self.calcTax是一个按钮,并且您想在按下该按钮时执行该功能,则应该输入以下内容:
self.calcTax.clicked.connect(self.CalculateTax)