[Tutor] click and line

Shi Mu samrobertsmith at gmail.com
Mon Nov 7 02:53:50 CET 2005


I tried to write the follwoing code to draw lines on the anvas based
on the clicked points but retur the message:
>>> Traceback (most recent call last):
  File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python23\test\Q_line.py", line 13, in ?
    l5=c.create_line(m1,n1,event.x,event.y,fill='blue',width='50')
NameError: name 'm1' is not defined

The ocde migth be naive,...
from Tkinter import *

root = Tk()

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

def click(event):
    print event.x, event.y
    m1=event.x
    n1=event.y
frame = c
c.bind('<Button-1>',click)
l5=c.create_line(m1,n1,event.x,event.y,fill='blue',width='50')

c.pack()

root.mainloop()


More information about the Tutor mailing list