Python Turte Pencolor()

Hi new member here.

I work at a science center teaching kids science and coding.
We have been using Python Turtle to solve puzzels, drawing using rgb color code as a part of the solution.
But yesterday we noticed that rgb color does not work instead you have to use values between 0.0 and 1.0 instead of 1-255. t.pencolor(0.34,0.4,0.98) instead of t.pencolor(34,55,255)

I tried to google the issue and search this community but found nothing .
Is this a bug or have I missed some changes to Turtle?

Hey @Epiphe, welcome to the forums!

It works perfectly for me, maybe this article could work for you!

Hey Hugo,

Thx for the fast reply :slight_smile:
What webbrowser do you use to run replit?
I tried similar guides but without success.

Here is an img of my code and the error msg.
I use google chrome.

Hey @Epiphe,

I use Chrome, maybe in 8-9 hours you get more responses that could help!

Hi @Epiphe thanks for your post.

I can replicate your error, and have made a Repl here for others to test too.

I think it might be an issue with the template, but will check with a fork of an older one and confirm.

Hi again @Epiphe

After checking with an older template and getting the same issue I dug deeper. Turns out the colormode is important.

import turtle

t = turtle.Turtle()
screen = turtle.Screen()
print(screen.colormode()) # it will be 1.0 or 255
screen.colormode(255) # this sets it to use 0-255 for each r,g,b

Hope this helps resolve your issue.


Thank you Ian that fixed it!

Out of curiosity, what has changed? We never had to set colomode() before and always used rgb255 .

Hi @Epiphe I’m honestly not sure but remembered something about float values between 0.0 and 1.0 being a setting. Maybe the default template has changed but it’s hard to confirm. Glad it resolved the issue for you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.