View Single Post
Old 11-25-2020, 02:21 PM   #4
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
You are not supposed to call a function when connecting to a siganl, you just reference the function object and it will be called later when the signal is emitted. So when you do it as below (the wrong way), you are calling the function:

Code:
button.clicked.connect(myfunction())
You simply replace it with this:

Code:
button.clicked.connect(myfunction)
Here you are just referencing the function object to be called later when needed.

But what if the function expects additional arguments? how to pass them without calling the function?

Here is where the partial function comes into play, it takes the function and the args and makes new function like object that have the args built inside (sort of) it so that you do not need to supply them.

Simply searching for "python partial" in google will give enough material for further explanation.
capink is offline   Reply With Quote