Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created August 15, 2023 07:30
Show Gist options
  • Save stephengruppetta/83aa617951aa08fe0b206ed95db66b6a to your computer and use it in GitHub Desktop.
Save stephengruppetta/83aa617951aa08fe0b206ed95db66b6a to your computer and use it in GitHub Desktop.
import functools
import turtle
import string
window = turtle.Screen()
window.tracer(0)
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)
window.update()
for character in typewriter_keys:
window.onkeypress(
functools.partial(type_letter, character),
character,
)
window.listen()
window.update()
turtle.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment