Pycharm中turtle的setup无定义问题解决方案

    技术2022-07-11  156

    问题起因:在学习嵩山老师的python语言程序设计基础的P48页实例代码2.2Python蟒蛇绘制程序的的时候,使用from turtle import * 时setup()无定义。 解决过程:开始是以为自己的turtle库的安装出了问题,但仔细考虑发现使用turtle.setup()的时候没有报错。

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

    但是使用

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

    会报错。然后我找到turtle的库,看了一下,找到了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: ...

    然后尝试使用Screen().setup()成功。 如下 码

    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)

    有大佬想要补充的可以评论提示! 随手记录。

    Processed: 0.013, SQL: 9