3

I am trying to work with the screen in turtle and am confused about the dimensions of the screen. So in this example:

import turtle

screen = turtle.Screen()
print(screen.screensize()) 
turtle.done()

Python prints the dimension of the turtle window to be (400,300). However, the screen looks much bigger on the desktop and when I move the turtle by 640 pixels to the right (from the center) or 540 pixels downwards then the edge of the screen is reached. This would indicate that the screensize is 1280 * 1080 pixels.

So my specific questions are:

  1. What information do I get from calling screen.screensize()
  2. When the turtle is moved, is it moved in pixels or is another metric used?

So many thanks in advance!

  • I only know that it is moved in pixels – Alex Liu 33214 May 17 '20 at 19:41
  • [turtle.Screen().screensize() not outputting the right screensize](https://stackoverflow.com/questions/60357667/turtle-screen-screensize-not-outputting-the-right-screensize) – david May 17 '20 at 20:01
  • Does this answer your question? [How can I change the size of my python turtle window?](https://stackoverflow.com/questions/56528067/how-can-i-change-the-size-of-my-python-turtle-window) – david May 17 '20 at 20:02

1 Answers1

3

Let's clear up some misconceptions about turtle window size:

First, the default window you get in standalone turtle is 50% of your display width and 75% of your display height. Which means that not everyone gets the same default window. Something to consider when writing turtle software for others.

You can set the window's size using the setup() method or function. You can get the current window size using the window_width() and window_height() methods or functions.

The screensize() method or function gets/sets the size of the backing store for the window. Generally, the return value is of no use to you, as the area the turtle can travel is the size of the window, so no backing store needed. It's there for folks who, for example, want a 500x500 window onto a 2000x2000 plane that the turtle can wander. Then scrollbars appear to allow you to move that peephole of a window about the larger plane.

You can modify many of turtle's default behaviors with a turtle.cfg file.

You can also find this in the turtle documentation: https://docs.python.org/3/library/turtle.html#screenspecific

cdlane
  • 33,404
  • 4
  • 23
  • 63
  • Thank you so much, that was exactly what I needed! One follow up question though: My display resolution is 3840 * 2160 and the default windowsize is 1280 * 1080. Wouldn't that make the default behaviour to get 33% of the width and 50% of the height? I have the windows 10 default scale set at 150%, maybe that influences it? – Another_coder May 19 '20 at 07:21