Qtimer and extra argument

Phil Thompson phil at riverbankcomputing.com
Wed Oct 26 05:55:55 EDT 2016


On 26 Oct 2016, at 10:36 am, luca72 via Python-list <python-list at python.org> wrote:
> 
> Hello i hope that yo can reply to this question also if the argument is pyqt
> 
> i have a simple test:
> def start_timer(self):
>        self.timer = QTimer()
>        testo = 'pressed'
>        self.timer.singleShot(1000, self.metto_testo)
> 
> def test(self, testo):
>        self.lineEdit.setText(testo)
> 
> 
> How i can pass the variable testo to the def test?
> If i use :
> self.timer.singleShot(1000, self.metto_testo(testo)
> i get error

Use a lambda...

    self.timer.singleShot(1000, lambda s: self.metto_testo(testo))

Phil


More information about the Python-list mailing list