Skip to content

Instantly share code, notes, and snippets.

@horvatha
Created January 6, 2023 06:29
Show Gist options
  • Save horvatha/aa928228ea822c3560a15dfdfed8dc8e to your computer and use it in GitHub Desktop.
Save horvatha/aa928228ea822c3560a15dfdfed8dc8e to your computer and use it in GitHub Desktop.
from functools import partial
import turtle
window = turtle.Screen()
def draw_polygon(sides, color):
turtle.color(color)
angle = 360/sides
for i in range(sides):
turtle.forward(50)
turtle.right(angle)
for sides, color in [(3, "red"), (4, "green")]:
window.onkey(partial(draw_polygon, sides, color), str(sides))
window.listen()
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment