Как изменить цвет фона в Python Turtle: методы и примеры

Чтобы изменить цвет фона в модуле Python Turtle, вы можете использовать следующие методы:

Метод 1: использование функции bgcolor()

import turtle
# Create a turtle screen
screen = turtle.Screen()
# Set the background color
screen.bgcolor("blue")
# Keep the turtle window open
turtle.done()

Метод 2: использование функции bgpic()

import turtle
# Create a turtle screen
screen = turtle.Screen()
# Set the background color
screen.bgpic("path/to/image.png")
# Keep the turtle window open
turtle.done()

Метод 3: использование класса Screen()

import turtle
# Create a turtle screen
screen = turtle.Screen()
# Set the background color
screen.bgcolor("#FFA500")  # Use hexadecimal color code
# Keep the turtle window open
turtle.done()

Метод 4. Использование класса Screen()с градиентным фоном

import turtle
# Create a turtle screen
screen = turtle.Screen()
# Set the gradient background color
screen.bgcolor("red")
screen.bgcolor("orange")
# Keep the turtle window open
turtle.done()