tkinter.mainloop 函数的 n 参数是什么? [英] What is the n parameter of tkinter.mainloop function?

查看:54
本文介绍了tkinter.mainloop 函数的 n 参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

n 参数可以给 tkinter.mainloop 函数,

A n parameter may be given to tkinter.mainloop function,

help(tkinter.Tk.mainloop)
>>>> mainloop(self, n=0) # What is n here ?
     Call the mainloop of Tk.

我找不到任何关于它的文档

I was not able to find any documentation about it

这个 n 参数的用途是什么?

What is the purpose of this n parameter?

推荐答案

正如您在 Tkinter 的 C 实现 中所见,_tkinter_tkapp_mainloop_impl,

As you can see in the C implementation of Tkinter , _tkinter_tkapp_mainloop_impl,

_tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)

n 表示传递给函数的threshold 参数.

n represent the threshold parameter passed to the function.

现在,看看实现本身,可以在函数的开头看到这个循环,

Now, looking at the implementation itself, it is possible to see this loop at the beginning of the function,

 while (Tk_GetNumMainWindows() > threshold &&
       !quitMainLoop &&
       !errorInCmd)

因此,您可以看到,当 root level 窗口的数量下降到 threshold 时,代码将退出 mainloop或以下.

Hence, you can see that the code is meant to drop out of the mainloop when the number of root level windows drops to threshold or below.

请注意,默认情况下,可选参数的值为 0,这在逻辑上意味着如果 any root 它将保持活动状态级别 窗口打开.

Note that by default the optional parameter will have a value of 0 which logically means it will stay active if any root level windows are opened.

更多信息

我无法评论为什么添加了这个 threshold 参数,但缺少关于这个特定参数的文档和/或信息很可能是因为很少有人会将 n 显式传递给 tkinter.mainloop 并更改默认行为.

I can't comment on why this threshold parameter was added, but the lack of documentation and/or information on this specific parameter most likely comes from the fact that it seems quite rare that someone would pass n explicitly to tkinter.mainloop and change the default behavior.

这篇关于tkinter.mainloop 函数的 n 参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆