'python turtle screen is not show correct

I'm python newbie, I used pyenv install python on my mac, my python version

➜  ~ python --version
Python 3.10.3

And this is my code

from turtle import Screen, Turtle

screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor("red")
screen.title("My Snake Game")

segment_1 = Turtle("square")
segment_1.color("white")

screen.exitonclick()

When I run this code

$ python main.py

The result is not I want

result

When I close the gui, I got this message

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Traceback (most recent call last):
  File "/Users/li/main.py", line 5, in <module>
    screen.bgcolor("red")
  File "/Users/li/.pyenv/versions/3.10.3/lib/python3.10/turtle.py", line 1238, in bgcolor
    color = self._colorstr(args)
  File "/Users/li/.pyenv/versions/3.10.3/lib/python3.10/turtle.py", line 1159, in _colorstr
    raise TurtleGraphicsError("bad color string: %s" % str(color))
turtle.TurtleGraphicsError: bad color string: red

How could I fix it, Thanks.



Solution 1:[1]

I found the solution, the tcl-tk version. Original tcl-tk version is 8.5.

I use brew to install tcl-tk

$ brew install tcl-tk

And reinstall python

$ pyenv uninstall 3.10.3
$ pyenv install 3.10.3

The tcl-tk version become 8.6

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lighter