I have two scripts files which are test_qt.py and test.py. I want to call a function when I press the push button. But this function it is not inside the Widget file(test_qt). I can call the function easily if it is inside the Widget file but if i try to call it out of the test_qt, I get this error "AttributeError: 'Ui_Form' object has no attribute 'test_something'". I have checked many examples but I havent solved yet. I want to call test_something() function. I dont know where is the mistake. I defined print_something() function to call the test_something()
#----test_qt.py----
from PyQt5 import QtCore, QtGui, QtWidgets
from test import*
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(150, 100, 93, 28))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.print_something)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
def print_something(self):
#strong textprint("click")
self.test_something()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
---------------------------
#---- test.py -------------
def test_something():
print("clicked")
---------------------------