global definition

S

Shi Mu

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()
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top