Skip to content
← Back to Community
Enhancing Python projects
Profile icon
SilvermoonCat

Enhancing Python Projects!

(´。• ω •。`)

by SilvermoonCat ♥

Hi! Do your python projects seem boring, or need, perhaps, a little more to them?
Maybe these will help you!

Information Covered

  1. Typewriter Effect
  2. Custom Colored text
  3. Cool Ways to Clear
  4. ASCII Text using a Module

Let's begin!

1. Typewriter Effect

This means that each letter is typed out, as if a person were typing it live.


note: There are many ways to do this!

Import...

import os import time import random #ONLY IF YOU WANT THE TYPING TO BE REALISTIC! import sys

Once those are imported, create a variable and start coding:

word = "" #variable! def typewriter(word): #you can modify "typewriter", it's a command name basically word for char in word: time.sleep(random.choice([0.04,0.05,0.03.7])) #to make it realistic sys.stdout.write(char) sys.stdout.flush() print("") #this is for a new line

Now, to use it, simply put in your code:

typewriter("Content is typed")

You can modify the "0.04, 0.05" Part. It's how long it pauses between typing each letter.

  • make sure not to make it TOO fast or else it hurts the eye (below 0.03)
  • If it's too slow, people become impatient (above 0.07)
  • Personally, I prefer 0.04-0.05

YAY

Full code

import os import time import random word = "" def typewriter(word): word for char in word: time.sleep(random.choice([0.04,0.05,0.03.7])) sys.stdout.write(char) sys.stdout.flush() print("") typewriter("Content is typed")

2. Custom Colored Text

You can add color to your text using ANSI escape codes I think they were called.
Here's a tutorial I made:https://replit.com/talk/learn/Python-Text-Styles/118062
It's not complete but I hope it will help!

3. Cool Ways to Clear

So, after the screen gets messy, it should be cleared!
Simply

import os def clear(): os.system("clear")

Now, whenever you use the clear() command in your code, it will clear the screen.
But that's kinda boring, isn't it?

You can get creative and make your own ways to clear! Here's one way I like to do it

import os def clear(): print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") os.system("clear")

This will create a bunch of new lines, so it seems like you're scrolling down... then... poof ... it's gone.
At least it's more exciting~
Have fun with it!
For example, you could make it...

  • print a little symbol on each new line then clear
  • using the import time, making it wait a few seconds

qwq I can't think of any more ideas but that's basically how you do it!

4. ASCII TEXT

ASCII is actually easy with the help of a module- pyfiglet!

very useful for lazy people like me

It's easy to use and quite convenient for ascii

import it

import pyfiglet

Using it

ascii_text = pyfiglet.figlet_format("ASCII TEXT") print(ascii_text)

This will have a normal output that looks like:
9718FC21-D739-4735-87F6-F764853824FF

Customization

So: right now your code looks like this:

import pyfiglet ascii_text = pyfiglet.figlet_format("ASCII TEXT") print(ascii_text)

FONTS!

anyone here addicted to fonts like me ;-;

Tis an easy thing to use here. Let's focus on the line:

ascii_text = pyfiglet.figlet_format("ASCII TEXT")

Let's try the font called "Bulbhead"
Now, after "ASCII TEXT", add...

ascii_text = pyfiglet.figlet_format("ASCII TEXT", font = "bulbhead")
That's how you add a font. Now, if we run the code, it should output:

__ ___ ___ ____ ____ ____ ____ _ _ ____ /__\ / __) / __)(_ _)(_ _) (_ _)( ___)( \/ )(_ _) /(__)\ \__ \( (__ _)(_ _)(_ )( )__) ) ( )( (__)(__)(___/ \___)(____)(____) (__) (____)(_/\_) (__)

I don't know all of the fonts, but this is a helpful website with a preview of each font
http://www.figlet.org/examples.html

And that brings this tutorial to an end!

kthxbye

Voters
Profile icon
BearCoder01
Profile icon
halo4936
Profile icon
Bookie0
Profile icon
InvisibleOne
Profile icon
OldWizard209
Profile icon
DynamicSquid
Profile icon
CyberPy
Profile icon
VulcanWM
Profile icon
SilvermoonCat
Comments
hotnewtop
Profile icon
BearCoder01

Nice. I have a other typer effect that make sound when it runs. Include also a text cursor.

https://replit.com/@BearCoder01/real-typer-effect-v-201#main.py

https://replit.com/@BearCoder01/real-typer-effect-v-201#main.py

Profile icon
SilvermoonCat

@BearCoder01 cool! there’s a lot of ways to make type writer effects :P

Profile icon
InvisibleOne

This is a great tutorial... but you should have included cowsay
Nothing brightens up some python like having a cow tell you how to play a terminal game
And it isn't just limited to cows!

Profile icon
SilvermoonCat

@InvisibleOne I’ll check that out! I didn’t know it existed :’( lmao

Profile icon
InvisibleOne
Profile icon
codingjlu

@InvisibleOne lolol I love it. It's default for nix repls

Profile icon
CyberPy

Noice. But there is one problem with your code...
You did this:

import os import time import random word = " def typewriter(word): word for char in word: time.sleep(random.choice([0.04,0.05,0.03.7])) sys.stdout.write(char) sys.stdout.flush() print("") typewriter("Content is typed")

It should be this:

import os import time import random import sys word = "" def typewriter(word): word for char in word: time.sleep(random.choice([0.04,0.05,0.03.7])) sys.stdout.write(char) sys.stdout.flush() print("")

Because you:

  • Forgot the second quotation mark,
  • And you didn't import sys

But still, nice tutorial, didn't know there was a module to "asciify" text

Profile icon
SilvermoonCat

@CodingEssence lol I haven’t coded in so long I forgot
tysm I’ll add that

Profile icon
CyberPy
Profile icon
VulcanWM

Nice!

Profile icon
SilvermoonCat

@VulcanWM thanks!

Profile icon
VulcanWM