click event

S

Shi Mu

I have the following workable code and every time i click on the
canvas, the coordinates are reported.
i wonder how i can draw the lines when i click the canvas using these
coordinates?

from Tkinter import *

root = Tk()

c = Canvas(root, bg='#0e2e0e', height=500, width=1000)

def click(event):
print event.x, event.y
frame = c
c.bind('<Button-1>',click)

c.pack()

root.mainloop()
 
J

jmdeschamps

I guess you mean draw lines from the laast coordinates to the new one?

then add a few global variables:

lastX=""
lastY=""

# and modify
lastX=""
lastY=""
def click(event):
global lastX, lastY
if lastX != "":
c.create_line(lastX,lastY,event.x,event.y,fill="white")
lastX = event.x
lastY = event.y
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top