-
-
Save stephengruppetta/a4aa89aad3a7cbbb03b1e6c5f09219c1 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
import functools | |
import turtle | |
import string | |
window = turtle.Screen() | |
typewriter = turtle.Turtle() | |
# Select keys that are on a typewriter | |
typewriter_keys = { | |
# unpack string.ascii_letters, string.digits, | |
# and string.punctuation into a set | |
*( | |
string.ascii_letters | |
+ string.digits | |
+ string.punctuation | |
) | |
# remove the minus sign and add "minus" | |
} - {"-"} | {"minus"} | |
# Define a function that takes a character as an argument | |
# and writes it to the screen | |
def type_letter(character): | |
if character == "minus": | |
character = "-" | |
typewriter.write(character, font=("Courier", 30, "normal")) | |
typewriter.forward(30) | |
for character in typewriter_keys: | |
window.onkeypress( | |
functools.partial(type_letter, character), | |
character, | |
) | |
window.listen() | |
turtle.done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment