可以给n
函数一个tkinter.mainloop
参数,
help(tkinter.Tk.mainloop)
>>>> mainloop(self, n=0) # What is n here ?
Call the mainloop of Tk.
我找不到任何有关它的文件
此参数的目的是什么?
最佳答案
正如您在Tkinter的C实现中看到的那样,_tkinter_tkapp_mainloop_impl
,
_tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)
n
表示传递给函数的参数。现在,看看实现本身,可以在函数的开头看到这个循环,
while (Tk_GetNumMainWindows() > threshold &&
!quitMainLoop &&
!errorInCmd)
因此,您可以看到,当根级别窗口的数量下降到
threshold
或更低时,代码将从mainloop
中退出。请注意,默认情况下,可选参数的值将为
threshold
,这在逻辑上意味着如果打开任何根级别的窗口,它将保持活动状态。更多信息
我不能解释为什么添加了这个
0
参数,但是缺少关于这个特定参数的文档和/或信息很可能是因为似乎很少有人将threshold
明确传递给n
并更改默认行为。关于python - tkinter.mainloop函数的n参数是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51386979/