click event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shi Mu

    #1

    click event

    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()
  • jmdeschamps@gmail.com

    #2
    Re: click event

    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(l astX,lastY,even t.x,event.y,fil l="white")
    lastX = event.x
    lastY = event.y

    Comment

    Working...