Python 在Tkinter中使用鼠标绘制选择区域

Python 在Tkinter中使用鼠标绘制选择区域,python,matplotlib,tkinter,Python,Matplotlib,Tkinter,我正在开发一个应用程序,它以.csv的形式从用户那里获取输入,并使用matplotlib为相应的值绘制图形 def plotgraph(): x = [] y = [] data = text.get("1.0", END) sepFile = data.split('\n') for plotPair in sepFile: xAndY = plotPair.split(',') if len(xAndY[0]) !=

我正在开发一个应用程序,它以
.csv
的形式从用户那里获取输入,并使用
matplotlib
为相应的值绘制图形

def plotgraph():
    x = []
    y = []
    data = text.get("1.0", END)
    sepFile = data.split('\n')

    for plotPair in sepFile:
        xAndY = plotPair.split(',')
        if len(xAndY[0]) != 0 and len(xAndY[1]) != 0:
            x.append(float(xAndY[0]))
            y.append(float(xAndY[1]))

    graph = Figure(figsize=(5,4), dpi=100)
    a = graph.add_subplot(111)
    a.plot(x,y)
    a.set_xlabel('Velocity')
    a.set_ylabel('Absorbance')
    canvas = FigureCanvasTkAgg(graph, master=RightFrame)
    canvas.show()
    canvas.get_tk_widget().grid(column=2, row=1, rowspan=2, sticky=(N, S, E, W))
我希望在
Tkinter
中有一个类似的函数,它在选择后为我提供
x0,x1,y0,y1
。我可以让已经提出的问题发挥作用,并根据我的需要定制它,但不知道我在
\uuuu init\uuuu(self)


当我运行这段代码时,我得到一个空白的Tk窗口。有人能告诉我我应该做什么吗?我犯了什么错误来使用列表中所列的类

class Annotate(object):
    def __init__(self):
        print "Annotate is runing"
        # rest of your code

root = Tk()
my_object = Annotate()

root.mainloop()

您可能需要做更多的工作。

您是否在console/terminal/cmd.exe中运行了此功能?可能有一些错误信息。如果是,则添加有问题的完整错误消息。您是否仅使用
root=Tk()
类注释(对象)
运行这部分代码?如果是,则只运行
root=Tk()
,您必须学习如何使用类。您的错误是:您没有使用class
Annotate
创建对象,因此python无法在
\uuuu init\uuuu
@furas中运行代码。我正在Spyder(有控制台)中运行代码。我正试着采纳你的建议&看看事情是否成功。谢谢你的建议。谢谢你的回答。我没有创建任何对象。现在,控制台中显示了初始坐标和最终坐标,但选择区域没有显示。您能看一下吗
class Annotate(object):
    def __init__(self):
        print "Annotate is runing"
        # rest of your code

root = Tk()
my_object = Annotate()

root.mainloop()