Hi everyone.
First of all, I am so sorry by my bad English.
I would be very grateful if you could help me with the following problem:
I am programming, in python, a GUI in which the user is allowed to click, with the mouse, any point on a graph. That event will produce certain information related to the point that was clicked, to indicate which trading actions should be taken.
The problem is that to produce the information of each point, it is necessary to convert the coordinates in pixels of the point to cartesian coordinates, that is, obtain the original x and y coordinates. Where x is an integer from xmin = 0 to xmax. While y is a real number, it ranges from ymin to ymax.
I get some values, but I can't get more or less precise values with the following instructions, which I have within the function that handles the mouse click event:
abs_coord_x = root.winfo_pointerx() - root.winfo_rootx()
abs_coord_y = root.winfo_pointery() - root.winfo_rooty()
width =root.winfo_width()
height = root.winfo_height()
xreal=(abs_coord_x*(xmax - xmin))/ width + xmin
yreal=((alto - abs_coord_y)*(ymax - ymin))/ height + ymin
Obviously, there are problems identifying the margins of the windows where I insert the graphic, but I don't know how to get those margins. The graphic is inserted into a window created with tkinter. With the following instructions it is observed that these coordinates can be obtained, but I do not see the way to use them in my program:
toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
Hopefully someone can help me with this.
A greeting.
Luciano