Answer the question
In order to leave comments, you need to log in
Python gives 'missing 1 required positional argument: 'self'', what should I do?
I know that there are a lot of such questions, but no matter how much I searched, I can not find the answer.
I am trying to make a dynamic countdown timer while executing the code along the way
I have the code:
class Class(object):
<задание параметров окна и вызов функции startCard через self.button.clicked.connect()>
def beginCard(self):
<выполняемый код>
self.threadBeginCard.join()
def startCard(self):
<выполняемый код>
self.threadBeginCard.start()
threadBeginCard = Timer(0.1, beginCard, args=None, kwargs=None)
class InputFrame(QtWidgets.QMainWindow, Class):
def __init__(self):
super().__init__()
self.setupUi(self)
def main():
app = QtWidgets.QApplication(sys.argv)
window = InputFrame()
window.show()
app.exec()
if __name__ == '__main__':
main()
Answer the question
In order to leave comments, you need to log in
threadBeginCard = Timer(0.1, beginCard, args=None, kwargs=None)
I have no idea what Timer() is, but I can guess what it does.
It calls beginCard() with no positional (args) or named (kwargs) parameters when some event occurs.
The problem is that you are calling a class method, i.e. actually Class.beginCard(). He needs to pass an instance of the class as the first parameter, i.e. self.
If you were to call an instance method, i.e.
c = Class()
c.beginCard()
Then self would be substituted automatically.
Conclusion: create a Timer() inside an instance method, and pass self.beginClass to it as a function. Note the absence of brackets.
True, I don't know what happens next - I don't really like the join() call, as it will block the UI thread until the worker thread finishes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question