/Demo/tkinter/guido/imagedraw.py

http://unladen-swallow.googlecode.com/ · Python · 23 lines · 18 code · 4 blank · 1 comment · 0 complexity · da4fb193d7f7d66de4931af0e53e382d MD5 · raw file

  1. """Draw on top of an image"""
  2. from Tkinter import *
  3. import sys
  4. def main():
  5. filename = sys.argv[1]
  6. root = Tk()
  7. img = PhotoImage(file=filename)
  8. w, h = img.width(), img.height()
  9. canv = Canvas(root, width=w, height=h)
  10. canv.create_image(0, 0, anchor=NW, image=img)
  11. canv.pack()
  12. canv.bind('<Button-1>', blob)
  13. root.mainloop()
  14. def blob(event):
  15. x, y = event.x, event.y
  16. canv = event.widget
  17. r = 5
  18. canv.create_oval(x-r, y-r, x+r, y+r, fill='red', outline="")
  19. main()