global definition

Shi Mu samrobertsmith at gmail.com
Mon Nov 21 04:23:00 CET 2005


I have a code here. I understand i can not draw lines without the
global definition of lastX and lastY. But still confused by its use.
when should we use global definition?

from Tkinter import *

root = Tk()

c = Canvas(root, bg='#0e2e0e', height=500, width=1000)
frame = c
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


c.bind('<1>',click)

c.pack()

root.mainloop()



More information about the Python-list mailing list