()
| 105 | return items |
| 106 | |
| 107 | def main(): |
| 108 | from random import shuffle |
| 109 | |
| 110 | canv = Canvas(width=500, height=500) |
| 111 | canv.create_rectangle(50, 50, 250, 150, fill='red') |
| 112 | canv.pack(fill=BOTH, expand=YES) |
| 113 | |
| 114 | rect = RectTracker(canv) |
| 115 | # draw some base rectangles |
| 116 | rect.draw([50,50], [250, 150], fill='red', tags=('red', 'box')) |
| 117 | rect.draw([300,300], [400, 450], fill='green', tags=('gre', 'box')) |
| 118 | |
| 119 | # just for fun |
| 120 | x, y = None, None |
| 121 | def cool_design(event): |
| 122 | global x, y |
| 123 | kill_xy() |
| 124 | |
| 125 | dashes = [3, 2] |
| 126 | x = canv.create_line(event.x, 0, event.x, 1000, dash=dashes, tags='no') |
| 127 | y = canv.create_line(0, event.y, 1000, event.y, dash=dashes, tags='no') |
| 128 | |
| 129 | def kill_xy(event=None): |
| 130 | canv.delete('no') |
| 131 | |
| 132 | canv.bind('<Motion>', cool_design, '+') |
| 133 | |
| 134 | # command |
| 135 | def onDrag(start, end): |
| 136 | global x,y |
| 137 | items = rect.hit_test(start, end) |
| 138 | for x in rect.items: |
| 139 | if x not in items: |
| 140 | canv.itemconfig(x, fill='grey') |
| 141 | else: |
| 142 | canv.itemconfig(x, fill='blue') |
| 143 | |
| 144 | rect.autodraw(fill="", width=2, command=onDrag) |
| 145 | |
| 146 | mainloop() |
| 147 | |
| 148 | if __name__ == '__main__': |
| 149 | try: |
no test coverage detected