Professional Documents
Culture Documents
2
2
Random colours
You can also randomly select colours like this:
# Print a line in a random colour
printc( randcol("This is a random colour") )
End of line?
By default, the printc() function adds a newline character at the end of its output, just like print().
You can change the end character in the same way as you would with the print function by
specifying an end argument as in the example below.
# Print each word in a random colour
mytext = "This is a random piece of text which I want to print in random colours"
mytext = mytext.split(" ")
for word in mytext:
printc(randcol(word), end=" ")
3. Select a new colour by clicking on the Choose colour for drop down and selecting a
colour from the palette:
4. Now open your copy of idlecolors.py file and change the USE_CUSTOM_COLORS value
to True. (Be aware that this will also allow all of the user defined colours to be randomly
chosen.)
USE_CUSTOM_COLORS = True # Change to True if you want to use custom colours
5. You can now use the colour you selected for "Python Definitions" as user1().
from idlecolors import *
printc( user1("New colour"))
If you wish, you can change the name of the colour by editing the idlecolors.py file - you will need
to edit both the colormap key and the function name.
Isn't this a really nasty hack?
Yes, yes it is.
Thanks
Credit for this idea came from this Stackoverflow thread. I made this because kids like colours. It's
not at all meant to be used for anything serious.