,可以通过以下步骤实现:
import tkinter as tk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
root = tk.Tk()
fig = Figure()
ax = fig.add_subplot(111)
def onclick(event):
x = event.xdata
y = event.ydata
print("鼠标单击坐标:", x, y)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
tk.mainloop()
这样,当在嵌入的matplotlib图中单击鼠标时,鼠标单击的坐标将会打印出来。
推荐的腾讯云相关产品:无
以上是获取鼠标单击坐标的方法,希望对您有帮助!
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云