Чтобы создать квадрат с модулем Turtle в Python и залить его черным, вы можете использовать следующие методы:
Метод 1. Использование встроенных функций модуля Turtle:
import turtle
# Create a turtle object
t = turtle.Turtle()
# Set the fill color to black
t.fillcolor("black")
# Begin filling the shape
t.begin_fill()
# Draw the square
for _ in range(4):
t.forward(100)
t.right(90)
# End the filling
t.end_fill()
# Close the turtle graphics window
turtle.done()
Метод 2. Использование функций seth() и fill() модуля Turtle:
import turtle
# Create a turtle object
t = turtle.Turtle()
# Set the fill color to black
t.fillcolor("black")
# Begin filling the shape
t.begin_fill()
# Set the heading to 90 degrees (facing up)
t.seth(90)
# Draw the square
for _ in range(4):
t.forward(100)
t.right(90)
# End the filling
t.end_fill()
# Close the turtle graphics window
turtle.done()