dr_zoidberg1 0 Newbie Poster

Hi everyone, i’m new to this board, and i’m having a bit of trouble plotting lines inside of a function, perhaps someone knows what i’m doing wrong!

I’m trying to plot an X where the points have been clicked, this is all for a wider picture that is going to be a Dijkstra or Prim’s algorithm application, but im trying to get the capturing done first.

(IDLE on Python 3.1)

from tkinter import *
XList = []
YList = []
def GetXY(event):
    XCoord = event.x
    YCoord = event.y
    if XCoord < 400 and YCoord < 400:
        SaveXandY(XCoord,YCoord)
    else:
        print("Out of Range")

def SaveXandY(X,Y):
    XList.append(X)
    YList.append(Y)
    # This will Save the X and Y data and then pass it to Algorithm

def XY(event):
    XCo, YCo = event.x, event.y
    XYTitle = "X Coord = %d  Y Coord = %d" % (XCo, YCo)
    window.title(XYTitle)

def Plot(XList,YList,window):
    for i in range (0,(len(XList))):
        canvas.create_line(((XList[i])-3),((YList[i])-3),((XList[i])+3),((XList[i])+3))

# Set Up Window & Bindings
window=Tk()
window.geometry("500x500")
canvas = Canvas(window,width=400, height=400, bg='white')
canvas.bind("<Button-1>", GetXY)
canvas.bind("<Motion>",XY)
canvas.pack()
FinishedButton = Button(window,text="Plot!", command=Plot(XList,YList,window))
FinishedButton.pack({"side":"bottom"})

# Main Loop
mainloop()

P.S. is there a more elegant way of approaching this, this was just something i threw together as an idea, but it doesn't look like the most efficient way of doing this?