[issue941262] List with Canvas.create_line Option arrow=LAST Broke

Guilherme Polo report at bugs.python.org
Sat Mar 28 21:03:05 CET 2009


Guilherme Polo <ggpolo at gmail.com> added the comment:

Hi Brian (hope you are still there), the code in 31_8.tcl is not
complete so I didn't bother looking into it.

The tkdraw.py is not really correct, here is a cleaned up version that
works:

from Tkinter import Tk, Canvas, LAST, ROUND

def StrokeBegin(event):
    print "clicked at", event.x, event.y
    del stroke[:]
    tuple = (event.x, event.y)
    stroke.append(tuple)

def Stroke(event):
    tuple = (event.x, event.y)
    coords = stroke[len(stroke)-1] + tuple

    stroke.append(tuple)
    canvas.create_line(coords, tag='segments')

def StrokeEnd(event):
    canvas.delete('segments')
    if len(stroke) < 2:
        # Just a click happened
        return

    canvas.create_line(stroke, tag='line', arrow=LAST,
            joinstyle=ROUND, smooth=1)

stroke = []

root = Tk()
canvas = Canvas(root, height=400, width=500)
canvas.bind("<Button-1>", StrokeBegin)
canvas.bind("<B1-Motion>", Stroke)
canvas.bind("<ButtonRelease-1>", StrokeEnd)
canvas.pack()
root.mainloop()

----------
nosy: +gpolo
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue941262>
_______________________________________


More information about the Python-bugs-list mailing list