What is the n parameter of tkinter.mainloop function?

前端 未结 1 1627
遥遥无期
遥遥无期 2021-02-07 05:18

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

help(tkinter.Tk.mainloop)
>>>> mainloop(self, n=0) # What is n her         


        
1条回答
  •  迷失自我
    2021-02-07 05:32

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

    _tkinter_tkapp_mainloop_impl(TkappObject *self, int 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)
    

    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.

    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.

    Further information

    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.

    0 讨论(0)
提交回复
热议问题