In this program, I tried to create a loop that would increase the value of the variable X during each iteration
from tkinter import *
def func(x=0):
    x +=1
    root.after(10, func, x)
    print(x)
           
root = Tk()
btn1 = Button(root, text="click", command=func)
btn1.grid()
root.mainloop()
When I press the button for the first time everything works correctly. But when I press the button again, I see something like this:
    1
    2
    3
    4
    5
    6
    7
    1
    8
    2
    9
    3 
    10
    4 
    11
    5 
    12
    6 
    13
    7 
    14
    8
    15
It looks like the old and new values of the variable are mixed.
I think I should remove the first func()run from mainloop() to do list.
But how?
 
     
    