Cannot pass arguments from the tkinter widget.after function

后端 未结 3 973
小鲜肉
小鲜肉 2020-12-19 10:14

Part of the GUI I\'m building using tkinter has a pop-up window that says \"Please wait while the program is running.\" then after it finishes the window goes away. I\'m usi

3条回答
  •  醉话见心
    2020-12-19 10:36

    When you do this:

    widget.after(10, self.runBackup(mybackup))
    

    ... You are telling Tkinter "run the command runBackup, and when it returns, use the result as an argument to after". Because runBackup returns None, the above is equivalent to:

    self.runBackup(mybackup)
    widget.after(10, None)
    

    Instead, you want to give after a reference to the function, rather than calling the function. If the command needs arguments, those can be given to after as additional arguments.

    For example:

    widget.after(10, self.runBackup, mybackup)
    

提交回复
热议问题