n可以给出一个参数来tkinter.mainloop起作用,
help(tkinter.Tk.mainloop)
>>>> mainloop(self, n=0) # What is n here ?
Call the mainloop of Tk.
Run Code Online (Sandbox Code Playgroud)
我无法找到任何有关它的文档
这个n参数的目的是什么?
sch*_*tte 16
正如您在Tkinter 的C实现中所看到的_tkinter_tkapp_mainloop_impl,
_tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)
Run Code Online (Sandbox Code Playgroud)
n表示threshold传递给函数的参数.
现在,看一下实现本身,可以在函数的开头看到这个循环,
while (Tk_GetNumMainWindows() > threshold &&
!quitMainLoop &&
!errorInCmd)
Run Code Online (Sandbox Code Playgroud)
因此,您可以看到代码意味着在根级别窗口mainloop的数量下降到或低于的时候退出.threshold
请注意,默认情况下,可选参数的值在0逻辑上意味着如果打开任何 根级别窗口,它将保持活动状态.
更多的信息
我不能评论为什么threshold添加这个参数,但是缺少关于这个特定参数的文档和/或信息很可能来自这样一个事实,即有人会n明确地传递tkinter.mainloop并更改默认行为.