龟。设置应用程序的初始窗口位置

时间:2019-05-18 20:40:27

标签: python turtle-graphics

我正在尝试为我的第一个乌龟脚本设置起始窗口,但是经过一番搜索之后,似乎没有一种干净的方法。

1 个答案:

答案 0 :(得分:0)

  

经过一些搜索之后,似乎没有干净的方法

干净 是什么意思?您可以使用setup()方法设置乌龟窗口的初始大小和开始位置:

>>> import turtle
>>> help(turtle.setup)
Help on function setup in module turtle:

setup(width=0.5, height=0.75, startx=None, starty=None)
    Set the size and position of the main window.

    Arguments:
    width: as integer a size in pixels, as float a fraction of the 
      Default is 50% of 
    height: as integer the height in pixels, as float a fraction of the
       Default is 75% of 
    startx: if positive, starting position in pixels from the left
      edge of the screen, if negative from the right edge
      Default, startx=None is to center window horizontally.
    starty: if positive, starting position in pixels from the top
      edge of the screen, if negative from the bottom edge
      Default, starty=None is to center window vertically.

例如:

from turtle import Screen, Turtle

screen = Screen()
screen.setup(300, 300, startx=100, starty=200)

turtle = Turtle()
turtle.dot(100)

screen.mainloop()