Solution to the undefined problem of turtle setup in Pycharm

Cause of the problem: When P48 page code examples 2.2Python python drawing program of learning Songshan teacher python programming language based, from turtle import * When using the setup () is not defined .
Turtle.setup() is undefined
Solution process: I thought that there was a problem with the installation of my turtle library, but after careful consideration, I found that there was no error when using turtle.setup().

import turtle
turtle.setup(650,350,200,200)

But use

from turtle import *
setup(650,350,200,200)

Will report an error. Then I found the turtle library, took a look, and found the relevant part of setup()

class _Screen(TurtleScreen):
    def __init__(self) -> None: ...
    # Note int and float are interpreted differently, hence the Union instead of just float
    def setup(
        self,
        width: Union[int, float] = ...,
        height: Union[int, float] = ...,
        startx: Optional[int] = ...,
        starty: Optional[int] = ...
    ) -> None: ...
    def title(self, titlestring: str) -> None: ...
    def bye(self) -> None: ...
    def exitonclick(self) -> None: ...

def Screen() -> _Screen: ...

Then try to use Screen().setup() successfully.
The following
Screen().setup()
code

from turtle import *
Screen().setup(650,350,200,200)
penup()
fd(-250)
pendown()
pensize(25)
pencolor("violet")
seth(-40)
for i in range(5):
    circle(40,80)
    circle(-40,80)
circle(40,80/2)
fd(40)
circle(16,180)
fd(40*2/3)

You can comment on the tips that you want to add!
Record at hand.

Guess you like

Origin blog.csdn.net/AQ_No_Happy/article/details/107065507