Turtle Graphics - 设置世界坐标后背景图像如何居中?

Turtle Graphics - how can background image in the center after setting the world cooridinates?

在使用海龟图形时,我通常将世界坐标设置为左下角。

import turtle
t=turtle.Pen()
turtle.setup(500,500)
turtle.setworldcoordinates(0, 0,500, 500)

挑战在于当我插入背景图片时

turtle.bgpic("cat.gif")

它也被移动到现在位于屏幕左下角的原始原点 (0,0)。我需要将图像的中心移动到我的 window 的中心。有这个办法吗?

如果你愿意稍微探讨一下 "beneath the shell",你可以在 tkinter 级别进行操作:

from turtle import Turtle, Screen

screen = Screen()
screen.setup(500, 500)
screen.setworldcoordinates(0, 0, 500, 500)

screen.bgpic("cat.gif")
canvas = screen.getcanvas()
canvas.itemconfig(screen._bgpic, anchor="sw")  # pylint: disable=W0212

turtle = Turtle()
turtle.dot(100)  # draw a large dot at (0, 0)

screen.mainloop()