When the window is open, I keep adding element to my list. I want to close the tkinter window automatically when my list length exceeds certain number, I couldn't get any good answer on internet.
Answers from How do I close a tkinter window? mostly close the tkinter window using button which is not the way I want.
I tried this code but it doesn't work
root = Tk()
#Some code....
#function to be called when mouse is clicked
def insertcoords(event):
#outputting x and y coords to console
coord.append([event.x, event.y])
#mouseclick event
canvas.bind("<Button 1>",insertcoords)
if len(coord) > 4 : #coord is my list
root.destroy()
root.mainloop()