MCPcopy Index your code
hub / github.com/python/cpython / _Screen

Class _Screen

Lib/turtle.py:3817–3943  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3815 return Turtle._screen
3816
3817class _Screen(TurtleScreen):
3818
3819 _root = None
3820 _canvas = None
3821 _title = _CFG["title"]
3822
3823 def __init__(self):
3824 if _Screen._root is None:
3825 _Screen._root = self._root = _Root()
3826 self._root.title(_Screen._title)
3827 self._root.ondestroy(self._destroy)
3828 if _Screen._canvas is None:
3829 width = _CFG["width"]
3830 height = _CFG["height"]
3831 canvwidth = _CFG["canvwidth"]
3832 canvheight = _CFG["canvheight"]
3833 leftright = _CFG["leftright"]
3834 topbottom = _CFG["topbottom"]
3835 self._root.setupcanvas(width, height, canvwidth, canvheight)
3836 _Screen._canvas = self._root._getcanvas()
3837 TurtleScreen.__init__(self, _Screen._canvas)
3838 self.setup(width, height, leftright, topbottom)
3839
3840 def setup(self, width=_CFG["width"], height=_CFG["height"],
3841 startx=_CFG["leftright"], starty=_CFG["topbottom"]):
3842 """ Set the size and position of the main window.
3843
3844 Arguments:
3845 width: as integer a size in pixels, as float a fraction of the screen.
3846 Default is 50% of screen.
3847 height: as integer the height in pixels, as float a fraction of the
3848 screen. Default is 75% of screen.
3849 startx: if positive, starting position in pixels from the left
3850 edge of the screen, if negative from the right edge
3851 Default, startx=None is to center window horizontally.
3852 starty: if positive, starting position in pixels from the top
3853 edge of the screen, if negative from the bottom edge
3854 Default, starty=None is to center window vertically.
3855
3856 Examples (for a Screen instance named screen):
3857 >>> screen.setup (width=200, height=200, startx=0, starty=0)
3858
3859 sets window to 200x200 pixels, in upper left of screen
3860
3861 >>> screen.setup(width=.75, height=0.5, startx=None, starty=None)
3862
3863 sets window to 75% of screen by 50% of screen and centers
3864 """
3865 if not hasattr(self._root, "set_geometry"):
3866 return
3867 sw = self._root.win_width()
3868 sh = self._root.win_height()
3869 if isinstance(width, float) and 0 <= width <= 1:
3870 width = sw*width
3871 if startx is None:
3872 startx = (sw - width) / 2
3873 if isinstance(height, float) and 0 <= height <= 1:
3874 height = sh*height

Callers 1

ScreenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…