Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tkinter - Drawing on an image

59 views
Skip to first unread message

Guido van Rossum

unread,
Jun 13, 1996, 3:00:00 AM6/13/96
to

> Does anyone know how Tkinter can be used to draw onto an image. I'd
> like to load the image onto a canvas and draw onto it.

There's an example in the Demo/tkinter/guido subdir.

Here it is:

"""Draw on top of an image"""

from Tkinter import *
import sys

def main():
filename = sys.argv[1]
root = Tk()
img = PhotoImage(file=filename)
w, h = img.width(), img.height()
canv = Canvas(root, width=w, height=h)
canv.create_image(0, 0, anchor=NW, image=img)
canv.pack()
canv.bind('<Button-1>', blob)
root.mainloop()

def blob(event):
x, y = event.x, event.y
canv = event.widget
r = 5
canv.create_oval(x-r, y-r, x+r, y+r, fill='red', outline="")

main()

--Guido van Rossum (home page: http://www.python.org/~guido/)

Dale C. Bertrand

unread,
Jun 13, 1996, 3:00:00 AM6/13/96
to

Does anyone know how Tkinter can be used to draw onto an image. I'd
like to load the image onto a canvas and draw onto it.

-Dale_Bertrand
Dale_B...@lems.brown.edu

Dale C. Bertrand

unread,
Jun 14, 1996, 3:00:00 AM6/14/96
to

Guido van Rossum writes:
> > Does anyone know how Tkinter can be used to draw onto an image. I'd
> > like to load the image onto a canvas and draw onto it.
>
0 new messages