Draw and erase shapes in Python with Turtle: Beginner Coding Tutorial

Опубликовано: 24 Июль 2026
на канале: Rivan
26
3

This is the code to draw and Clear a red square using buttons in Python.

import turtle
t = turtle.Pen()
def redsq50():
turtle.color(1,0,0)
turtle.begin_fill()
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.end_fill()


from tkinter import *
tk = Tk()
btn = Button(tk, text = "red square", command=redsq50)
btn.pack()
def clearscreen():
turtle.clear()
turtle.reset()


btn = Button(tk, text = "Clear all", command=clearscreen)
btn.pack()