python - .after() 方法递归

标签 python recursion tkinter

多次遇到类似的代码结构,当我在 threading.Thread 实现中看到这一点时,我只需要问一下 self.master.after( 100, self.periodicCall) 消耗越来越多的内存,因为它是一个递归函数调用......是的,不是吗?

class arbitraryClass():
    def __init__(self, master):
        ... # other miscellaneous codes not shown here
        self.periodicCall() # within the __init__() method

    def periodicCall(self): 
        self.doSomething() #arbitrary method
        self.master.after(100, self.periodicCall)
        ... # other miscellaneous codes not shown here

最佳答案

periodicCall 方法不直接调用自身;这不是递归调用。

它请求 tkinter 事件循环在给定时间内调用该方法;无需担心内存消耗。

关于python - .after() 方法递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27745184/

相关文章:

python - 闪烁的 Tkinter 标签

python请求POST 400错误

python - Python3 Selenium Webdriver在初始化期间超时

python - Django render_to_string <body><head> 标签

java - Sierpinski 地毯使用堆栈而不是递归

recursion - 理解 Elixir 中的递归

python - 如何在 tkinter 文本小部件中突出显示文本

python - 如何安装在Mac OS 10.11中的python-的OpenCV

recursion - Lua第四版编程中的八皇后之谜

python - 透明颜色 Tkinter