Suppose I to write a function get_coords which prompts the user for some input coordinates. One way to do this would be as follows:
def get_coords():
coords_string = input("What are your coordinates? (x,y)")
coords = tuple(coords_string)
return coords
However, I'd like to use this using a GUI rather than the command line. I've tried the following:
def onclick(event):
return (event.x, event.y)
def get_coords_from_figure():
fig = plt.figure()
plt.axvline(x=0.5) # Placeholder data
plt.show(block=False)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
However, using coords = get_coords_from_figure() results in a coords variable which is empty, unlike if I use coords = get_coords(), because the input function waits for user input.
How could I prompt a user for input using a GUI?