python中如何给turtle库设置颜色?

    科技2022-09-03  138

    python中如何给turtle库设置颜色?

    当使用 turtle.pencolor(100, 100, 100)设置颜色时,将会有turtle.TurtleGraphicsError: bad color sequence: (100, 100, 100)告警提示。导致程序无法运行下去。解决方案有:

    1.turtle有两种色彩模式,缺省1.0,即RGB范围在0-1。如果我们想设定在(red,green, blue)的三色设定模式,需要首先模式切换:

       模式切换:参数填1.0或255

    turtle.colormode(1.0) turtle.colormode(255)

     这时就可以使用:

    turtle.pencolor(255,0,0)

    使用我们熟悉的3个255方式设定颜色了,否认就会出现‘bad color sequence’的告警。

    2.another way:

    无论我们设置在哪种模式下,都可以使用下面两种方式,进行设定:

    turtle.pencolor('red') turtle.pencolor('#ff0000')

    喜欢有用的话,就点赞、评论吧!

    Processed: 0.010, SQL: 9