How to make a print statement to blink only once in Python 3? - python-3.x

I need to blink my print statement only once.
So now I have:
from termcolor import colored, cprint
blue = colored(', IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII', 'blue', attrs=['blink'], )
print(blue)
It keeps blinking , but I want it only once.
thank you

It's your terminal that makes text with certain attribute blink. You cannot control it. If you want to blink once, draw a text, wait, draw the text over the same position differently.

Related

Changing text color on output

I have written a text based game for the class I am taking, but I want to see how I can change certain output text to different colors. Say the villain loses, the text prints out red or something, and vice versa, if he wins, the text prints out in like blue. Do I need to define all the colors first, or is there a way to add it to the string? example:
print('Thank you for playing but unfortunately you lost your life!')
How can I change the output to red text?
is this python?
If so here is a link to a few options python colors
in your case I guess you want to have something like:
text = colored('Thank you for playing but unfortunately you lost your life!', 'red', attrs=['reverse', 'blink'])
print(text)
I'm basing my game off Game of Thrones. Here a sample of the output when the character loses. I'm still working on the story.
else:
print('\nOh dear! You did not collect all of the items!')
print('You were caught by Daenerys and set on fire by Drogon!')
print('Drogon escaped and set the township on fire!')
print('Thank you for playing but unfortunately you lost your life!')
print('You must start over')

How to print text with multiple different types of colors in he same line in Python 3?

I am trying to do some visualizing data on the terminal and I am doing lots of printing to do that. The issue I am having is that certain character symbols look the same. I figured that coloring them differently would help me see the differences. I see from this link that there is a way to do it, but I don't understand what I am looking at. There is no explanation for what is going on in those solutions.
How do you specify, in the same line, text with different colors?
I should also mention that I am building the printable string OUTSIDE of the call to print(). How do you build the colorful string outside of the print() call?
A rewritten form of my question:
1. Colorize the text I print to the string with multiple types of colors.
2. Colorize the string BEFORE it gets sent to the "print()" call.
A couple examples would be great.
Using colorama just like the answer you linked is doing:
from colorama import Fore, Style
my_str = f"{Fore.BLUE}Hello, {Style.RESET_ALL} guys. {Fore.RED} I should be red."
print(my_str)
This gives me:
As you can see Fore.<color name> changes the color of the text after it, until the Style.RESET_ALL. After that you can change the color of the text again.
There could be multiple ways to achieve this. One which doesn't require any extra packages is to use ANSI color codes. Look at this link. Below are some examples.
s = "\033[1;32;40m Bright Green on black \033[1;31;43m Red on yellow \033[1;34;42m Blue on green \033[1;37;40m"
print(s)
Here in first code \033[1;32;40m, \033[ is the escape code followed by 1 for bold, 32 for bright green text and 40 for black background. The 3 codes are separated by ; and ended with m. Adding all the 3 codes (1, 32 and 40 here) isn't mandatory though.
output:
Other ways to achieve this can be found here.

How to change Python background to a certain colour with colorama?

I am using colorama to change the colour of my text and it works fines, but now I want to change the colour of the whole background instead of just my text.
I am using Windows:
import colorama
from colorama import Fore, Back, Style
colorama.init()
print(Back.GREEN)
print(Fore.RED)
But, that code only makes the text coloured. Is there a way to do that in python? I want it like CMD where you can have the background of it a colour. I cannot use the OS module as I do not have admin rights, but I'm open to using any other module.
How do I solve this problem?
After a while in playing with it i figured it out. Just forgot about this post. Here is what I did.
import colorama
from colorama import Back as bg
colorama.init()
print(bg.RED)
print(colorama.ansi.clear_screen())
I think clearing the screen fixed the Issue
After playing with colorama on my Windows 10 box it seems it's only used to change the text but not the console/terminal background. I was however able to change the background using this standard library solution:
import ctypes
try:
ctypes.windll.msvcrt.system(b"color 4f")
print("Hello World!")
except ValueError:
pass
The terminal background will change to red with white text.

How to print in colours in the shell (PYTHON)

I am studying tech in Australia, and I am having trouble with getting this to print in colour. I would like to print the 'x's on the board in black (not blue), and so the numbers appear in blue ( in another part of the code). How do I print in black?
# creates the 'x's to display on the minesweeper board
for i in range(board_row):
board.append(["x"] * board_row)
ASCII and ANSI don't work, and I can't figure out how to get the modules like Blessings and colorama in to python

display.newText isnt working

first time user of Stackoverflow;
Problem: even at the basic level of trying to print out simply Hello world nothing seems to happen.
using this:
local text = display.newText("helloworld", 50, 50, native.systemFont, 24)
print(text)
the varible "text" when printed holds the value of "Table: 010F3E50" which changes on each reload
im new to this language and this is really annoying - Any help would be fantastic
Cheers
Actually, you are trying to print the object. Not the text inside. So try:
print(text.text)
Instead of:
print(text)
Keep coding............ :)
The color of the text might be black by default which might be the same color as the background in the simulator. Meaning it's visible but you just can't see it!
Trying changing the color of the text object by doing this:
text:setFillColor(1,0,0) -- red text

Resources