What is the n parameter of tkinter.mainloop function?

  • A+

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

What is the purpose of this parameter?


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 toplevel 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 top-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.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: