Learn to Code via Tutorials on Repl.it!

← Back to all posts
How to Make Your Own Python Color Changer Like COLORAMA!!
h
elipie (294)

Once again, another tutorial!

How to make this:

So, we can make text Colorfullll and pretttyyy
eprint("Hello My name Is Jeff", "red")

Well so first your going to have to have this basic colors.

blue="\033[0;34m"
cyan="\033[0;36m"
white="\033[0;37m" 
green="\033[0;32m"
orange ="\033[0;33m"
pink = "\033[0;31m"
black = "\033[0;30m"
purple = "\033[0;35m"
Do you want more??

All the colors in bold!!

bold_blue = "\033[1;34m"
bold_cyan="\033[1;36m"
bold_white="\033[1;37m" 
bold_green="\033[1;32m"
bold_orange ="\033[1;33m"
bold_pink = "\033[1;31m"
bold_black = "\033[1;30m"
bold_purple = "\033[1;35m"

Even more!?

bold = "\033[1m" 
reset  = "\033[0m"
dim = "\033[2m"
underline = "\033[4m"
bg = "\033[44m"

Of course, I won't be using those since this is a BASIC tutorial, but, you can implement them because this can teach you!

Starting off!

Make a new file called: <yourcolorchangernamehere>.py

Then in that file put:

def name(text, color):

Ok now I know some of you want to follow the exact same thing of the tutorial DO NOT!!!!! Call that function whatever you want DON'T NAME IT NAME!!!!!!

Ok so what does this do? Well it creates a function called name() which will be our base function, and creates two paramaters called text and color. This means when you call the function you will have to put the text (name("Hello")) and color (name("Hello","red")) So just to clarify, the COLOR is the second paramater and it has to be, unless you change the order in the actual function

Ok well you might be thinking: "Uh, this doesn't have any color in it. When it is a COLOR TUTORIAL!!!!!!!" Well here is how you add the color:

  if color == "blue":
    print(blue+text)
  elif color == "cyan":
    print(cyan +text)
  elif color == "white":
    print(white+text)
  elif color == "green":
    print(green+text)
  elif color == "orange":
    print(orange+text)
  elif color == "pink" or color == "red":
    print(pink+text)
  elif color == "black":
    print(black+text)
  elif color == "purple":
    print(purple+text)

Make sure to indent this correctly in the function, otherwise you will get an error!!
So what do you have so far?

blue="\033[0;34m"
cyan="\033[0;36m"
white="\033[0;37m" 
green="\033[0;32m"
orange ="\033[0;33m"
pink = "\033[0;31m"
black = "\033[0;30m"
purple = "\033[0;35m"

def eprint(text, color):
  if color == "blue":
    print(blue+text)
  elif color == "cyan":
    print(cyan +text)
  elif color == "white":
    print(white+text)
  elif color == "green":
    print(green+text)
  elif color == "orange":
    print(orange+text)
  elif color == "pink" or color == "red":
    print(pink+text)
  elif color == "black":
    print(black+text)
  elif color == "purple":
    print(purple+text)

So now if you go to main.py And do this:

from colorchanger import name

So you are importing the file :DD
Now you can add whatever you want, it is just a bunch of if statements, so some example code would be:

elif color == "bold_blue":
  print(bold_blue+text)

But you can add decorators like dim
and stuff like that.

Now if you want to make it into a package...
I suggestion using @IreTheKID 's package template

Thanks for reading!!

And I can thank my friend @HenryMartin4 's help because he helped me create ecolor so I can make this great tutorial

BYE COMMENT SUGGESTION :D:D:D:D:D

Commentshotnewtop
CodeLongAndPros (1465)

I don't see any "edit", for one.

Also, why?
If you're piping this it'll clog up -, and if you're printing to stderr, don't. Honestly, colors are overrated.

elipie (294)

@CodeLongAndPros oh, sorry. I don't want to anger you, some people were interested in it, and I don't know what you mean by:

I don't see any "edit" for one.

CodeLongAndPros (1465)

@elipie when you say "text editor", my mind goes to Vim, then EMACS; yet there is nothing like that here.

elipie (294)

@CodeLongAndPros ohhhhh okay, yeah i guess i should just rename it...? please don't ban me

CodeLongAndPros (1465)

@elipie Wait what? I don't have my Moderator hat on now…

elipie (294)

@CodeLongAndPros oh, i just get nervous around mods cause like getting banned from where you do your main coding is like a big deal for me

CodeLongAndPros (1465)

@elipie No, you get banned from:

  • upvoting
  • commenting
  • posting

Only the Repl.it team can ban you from coding.
And I'd ban you if and only if:

  • you advertise anything commercial
  • curse / slander
  • ban evade
  • Hurt others- like delete code.
KayPey (7)

Right on man. ColorrrRs are nice, indeed.

elipie (294)

@KayPey thanks can you rate it out of 10? It would tell me what I need to work on