Create a mini drawing board using Python Turtle
- DeTech Theory
- Jul 14, 2022
- 1 min read
Have you ever wondered if you could create a drawing canvas using code? Python Turtle lets you do just that!
Python Turtle is a pre-installed Python library that enables users to create pictures and shapes on a virtual canvas. Fun Fact: The little on-screen pen is called “Turtle” which is where the software gets its name from. This mini tutorial shows you how you can go a step further from pre-drawn figures, and move onto making your mouse a drawing tool!
Here's the code snippet used:
import turtle
def drag_func(x,y):
turtle.ondrag(None)
turtle.setheading(turtle.towards(x,y))
turtle.goto(x,y)
turtle.ondrag(drag_func)
turtle.speed(10)
scr = turtle.Screen()
scr.setup(600,600)
turtle.ondrag(drag_func)
scr.mainloop()
If you want to keep seeing posts and tips like these, do follow our Instagram page @detectheory !
Best,
Vasundhara
Comments