Pyhton: Want to get the mouse coordinate in a while loop : I would like to get the mouse click coordinate for several images. This is my code:

    j = 0
    while j < nb_images:
        plt.ion()
        fig = plt.figure()
        coords = []
        #Affichage
        plt.imshow(img[j], cmap="gray")
        plt.draw()

        while len(coords) <1:
            cid = fig.canvas.mpl_connect('button_press_event', onclick)

        print(coords[0][0], coords[0][1])
    j = j + 1

    def onclick(event):
        global ix, iy
        ix, iy = event.xdata, event.ydata
        global coords
        coords.append((ix, iy))
        if len(coords) == 1:
            fig.canvas.mpl_disconnect(cid)
            plt.close()
        return coords

The problem is that I cannot click on the figure to get the coordinate. The figure is busy. How I can fix it?
Thank you