Created
January 6, 2023 06:29
-
-
Save horvatha/aa928228ea822c3560a15dfdfed8dc8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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