diff --git a/reticule.py b/reticule.py index 668c619..4895785 100644 --- a/reticule.py +++ b/reticule.py @@ -20,6 +20,9 @@ # +RETICULE = 'reticule_tag' + + class Reticule: def __init__(self, canvas, width, height, radius_x=35, radius_y=20, color='green'): @@ -58,11 +61,11 @@ class Reticule: w, h = self.width, self.height coords = self.get_reticule_coords(w >> 1, h >> 1) # Center. - append(canvas.create_line(*next(coords), fill=self.color)) - append(canvas.create_line(*next(coords), fill=self.color)) - append(canvas.create_line(*next(coords), fill=self.color)) - append(canvas.create_line(*next(coords), fill=self.color)) - append(canvas.create_oval(*next(coords), outline=self.color)) + append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color)) + append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color)) + append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color)) + append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color)) + append(canvas.create_oval(*next(coords), tags=RETICULE, outline=self.color)) def set_reticule(self, x, y): self.xy_cache = x, y @@ -73,6 +76,17 @@ class Reticule: def handle_set_event(self, event): self.set_reticule(event.x, event.y) + def hide(self): + self.canvas.itemconfig(RETICULE, state=HIDDEN) + + def show(self): + self.canvas.itemconfig(RETICULE, state=NORMAL) + + def toggle(self): + current_state = self.canvas.itemconfig(RETICULE, 'state')[4] + new_state = NORMAL if current_state == HIDDEN else HIDDEN + self.canvas.itemconfig(RETICULE, state=new_state) + if __name__ == '__main__': from tkinter import *