更改 Turtle Graphics window 的屏幕位置?

Change the on-screen position of the Turtle Graphics window?

是否可以更改乌龟控制台在屏幕上的位置?

我的主要objective是写可以移动window的代码,仅此而已

我在 Windows 10.

下使用 Python 3.4.0

如果需要任何额外信息,请询问。

是的。您需要获取包含乌龟用作其 TurtleScreen. Once you have that window you can change its geometry 的 Tkinter Canvas 的根 window。

这是一个简单的演示。

import turtle

turtle.setup(width=0.5, height=0.5)
screen = turtle.Screen()

width, height = screen.window_width(), screen.window_height()
canvas = screen.getcanvas()

left, top = 30, 100
geom = '{}x{}+{}+{}'.format(width, height, left, top)
canvas.master.geometry(geom)

t = turtle.Turtle()
turtle.exitonclick()

为什么人们 总是 在阅读 turtle 文档之前跳入 tkinter

是的,您可以设置海龟图形的屏幕位置 window 使用与调整大小相同的 setup() 方法:

from turtle import Turtle, Screen

def animate():
    global offset

    screen.setup(width=0.333, height=0.333, startx=offset, starty=offset)

    turtle.dot(offset)

    offset += 10

    if offset < 300:
        screen.ontimer(animate, 100)

screen = Screen()

turtle = Turtle()

offset = 30

animate()

screen.exitonclick()

startx,如果为正,则为距屏幕左边缘的起始位置(以像素为单位),如果为负,则为距右边缘的起始位置。类似地,starty,如果为正,则为从屏幕顶部边缘开始的位置,如果为负,则为从底部边缘开始的位置。默认情况下,window 位于屏幕中央。

您的标题询问 Turtle Graphics window 在屏幕上的位置,但 body你的问题是关于 Turtle Console。这些可能被认为是两个不同的 windows.

My main objective is to write code that can move the window

我不知道你是只想设置 window 的初始位置还是实际在屏幕上移动 window 所以我重写了我的示例以演示后者。