Skip to content Skip to sidebar Skip to footer

What Is The N Parameter Of Tkinter.mainloop Function?

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

Solution 1:

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 anyroot 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.

Post a Comment for "What Is The N Parameter Of Tkinter.mainloop Function?"