Okay, so I've got a simple system worked up that allows students
(these are "CS0" non-CS-majors) to manipulate objects with commands
in the IDLE command window. The file is attached.
The next thing I'd like to do is define a function mouse() that
starts the main loop, waits for a mouse click, stops the main loop,
and returns the coordinates of the mouse click. Any suggestions?
#!/usr/local/bin/python
# Simple graphics module for Perspectives in Computer Science
# Peter Drake
from Tkinter import *
from operator import *
##def tag(text):
## tag.count += 1
## return text + str(tag.count)
##
##tag.count = 0
def set_background(color):
'''Sets the background color of the graphics window'''
canvas.config(background=color)
root.update()
def line(*points):
'''Draws (and returns) a line through points'''
id = canvas.create_line(reduce(add, points))
root.update()
return ['line', id]
def oval(upleft, downright):
'''Draws (and returns) an oval in the rectangle
bounded by upleft and downright'''
id = canvas.create_oval(upleft + downright, fill='black')
root.update()
return ['oval', id]
def polygon(*corners):
'''Draws (and returns) a polygon through points'''
id = canvas.create_polygon(reduce(add, corners))
root.update()
return ['polygon', id]
def text(location, string):
'''Draws (and returns) text centered at location'''
id = canvas.create_text(location[0], location[1], text=string)
root.update()
return ['text', id]
def fill(shape, color):
'''Sets the fill color of shape'''
if shape[0] not in ['line', 'text']: # Lines don't have fill color
canvas.itemconfig(shape[1], fill=color)
root.update()
def outline(shape, color):
'''Sets the outline color of shape'''
if shape[0] in ['line', 'text']:
canvas.itemconfig(shape[1], fill=color)
else:
canvas.itemconfig(shape[1], outline=color)
root.update()
def mouse():
'''Waits for a mouse click and returns its coordinates'''
# How do I do this?
pass
root = Tk()
canvas = Canvas(root)
canvas.pack()
root.update()
print "If you can't see the graphics window,"
print "it's probably at the upper left"
print "of your screen, behind this one."
Peter Drake
Assistant Professor of Computer Science
Lewis & Clark College
http://www.lclark.edu/~drake/
_______________________________________________
Edu-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/edu-sig