I wanted to know about the optional integer parameter for the mainloop()
function.
There is no documentation about this on python.org nor youtube.
The First Code: passing no parameters in mainloop
from tkinter import *
def fun():
global i
print("hello", i)
i += 1
root.mainloop()
print("Hi", i)
return
i = 0
root = Tk()
button1 = Button(root, text="click", command=fun)
button1.pack()
root.mainloop()
print("end")
Output: clicked button 3 times and closed window
hello 0
hello 1
hello 2
Hi 3
Hi 3
Hi 3
end
The Second code: passing i in mainloop
from tkinter import *
def fun():
global i
print("hello", i)
i += 1
root.mainloop(i)
print("Hi", i)
return
i = 0
root = Tk()
button1 = Button(root, text="click", command=fun)
button1.pack()
root.mainloop(i)
print("end")
Output: clicked button 3 times and closed window
hello 0
Hi 1
hello 1
Hi 2
hello 2
Hi 3
end
the codes without parameters are working in a suspicious manner which I believe is could be due to recursion.