Bu örnek, bilgisayarınızı bir kağıt ve farenizi bir delgeç gibi kullanmanıza izin verir. Kullanıcı ekranda herhangi bir yere tıklayabilmeli ve orada delikler (ovaller) oluşturabilmelidir.

Hole puncher demo

HOLE_RADIUS sabiti, delinecek olan her deliğin yarıçapını temsil eder. 10, bunun için iyi bir boyuttur.

Çözüm

"""
File: hole_puncher.py
---------------------
This program lets you click anywhere on the canvas to
"punch a hole" (e.g. draw a black circle there).
"""
from graphics import Canvas
HOLE_RADIUS = 10
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Hole Puncher")
    # animation loop
    while True:
        clicks = canvas.get_new_mouse_clicks()
        for click in clicks:
            draw_hole(canvasclick.xclick.y)
        canvas.update()
    canvas.mainloop()
def draw_hole(canvasxy):
    """
    Draws a circle on the canvas centered at the given location.
    """
    oval = canvas.create_oval(x - HOLE_RADIUSy - HOLE_RADIUS,
                              x + HOLE_RADIUSy + HOLE_RADIUS)
    canvas.set_color(oval'black')
if __name__ == "__main__":
    main()
X