Python Forum
Change the color automatically
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change the color automatically
#1
Hi, I am new to Python, and was wondering if it was possible to change the color automatically in the program. In fact, it would be to change the color in a loop. Could you enlighten me?
PS: Responses in French are also welcome.
Reply
#2
You want to change the color of what?
Reply
#3
The color of the pen, in the turtle.
Reply
#4
The official documentation of the turtle module starts with a colorful example. In python 3.8, there is also a turtledemo module with several examples that you can run.
Reply
#5
https://docs.python.org/3/library/turtle...e.pencolor Wrote:turtle.pencolor(*args)
Return or set the pencolor.

Four input formats are allowed:

pencolor()
Return the current pencolor as color specification string or as a tuple (see example). May be used as input to another color/pencolor/fillcolor call.

pencolor(colorstring)
Set pencolor to colorstring, which is a Tk color specification string, such as "red", "yellow", or "#33cc8c".

pencolor((r, g, b))
Set pencolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()).

pencolor(r, g, b)
Set pencolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0..colormode.

If turtleshape is a polygon, the outline of that polygon is drawn with the newly set pencolor.

 >>> colormode()
 1.0
 >>> turtle.pencolor()
 'red'
 >>> turtle.pencolor("brown")
 >>> turtle.pencolor()
 'brown'
 >>> tup = (0.2, 0.8, 0.55)
 >>> turtle.pencolor(tup)
 >>> turtle.pencolor()
 (0.2, 0.8, 0.5490196078431373)
 >>> colormode(255)
 >>> turtle.pencolor()
 (51.0, 204.0, 140.0)
 >>> turtle.pencolor('#32c18f')
 >>> turtle.pencolor()
 (50.0, 193.0, 143.0)
Reply
#6
Ok thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 990 Oct-25-2023, 09:09 AM
Last Post: codelab
  simplekml change shape&color issac_n 2 2,825 Aug-20-2022, 07:15 PM
Last Post: Joseph_Paintsil
  Use of input function to change screen background color in Turtles Oldman45 3 4,863 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  Change Text Color Output in Python bluethundr 2 8,720 Mar-06-2019, 10:23 PM
Last Post: bluethundr
  random change of color pixel with PIL louloudevinci 4 8,461 May-31-2018, 03:55 PM
Last Post: louloudevinci
  subprocess.call change color of shell Aquaplant 8 11,018 Jan-20-2017, 02:35 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020