I know how to change the font colour of output in Python using this (for example)
print('\033[94m' + text)
However, the rest of the text will then stay that colour, even after the app has closed. I could set it to a certain colour, but the user may have changed the background colour and that would be a problem,
print('\x1b\x63') # Esc c
This will reset the terminal (RIS).
Related
I am making my own terminal and I want to change all text colors to the user input. Please help me!
You are going to have to provide way more context for this question. What do you mean by making your own terminal? Are you building a terminal application or are you customizing a terminal?
If you mean you are running a python application and want to color the output of the script then consider using colorama
https://pypi.org/project/colorama/
You can use ANSI_escape_code like this: \033[CODE_HERE;ANOTHER_CODE_HEREmYOUR_CONTENT_HERE.
Example for bold + blinking text (\033[0m is to reset display to default values):
print("\033[1;5mdede\033[0m")
Another example:
print("\033[1;41mRed bold text\033[0;41mRed normal text\033[0mnormal text")
Will result to:
[]
I have zero experience with python, but it is clear enough (for most of the code).
There is this code:
from moviepy.editor import *
video = VideoFileClip("myHolidays.mp4").subclip(50,60)
# Make the text. Many more options are available.
txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color='white')
.set_position('center')
.set_duration(10) )
result = CompositeVideoClip([video, txt_clip]) # Overlay text on video
result.write_videofile("myHolidays_edited.webm",fps=25) # Many options...
What I want to do:
replace my whole video with a text centered and bold (maybe with some little effects) and some solid color background
How do I do that?
A* if I delete the "subclip(50,60)" part, will that select the whole clip?
B* And if I delete ".set_duration(10)", will the rest of the code work?
C* how do I delete the whole (previous) video content?
D* please suggest a simple pro effect (for text)
If you are trying to create a video of just the text the same length as the original video just find the length of the whole video, set the length of the text clip to the same and then txt_clip.write(...
I am currently plotting figures with xmgrace from python using GracePlot.py and I would like to make text annotations in the graph and place them inside a box, in order to make the reading easy when the grid is on.
Does anybody know how to do it with GracePlot.py? Or from xmgrace GUI?
The code I use is similar to the following:
import GracePlot as xg
import math
from numpy import arange
x=arange(0,10,0.1)
y=[math.exp(-q) for q in x]
grace=xg.GracePlot()
graph=grace[0]
data=xg.Data(x=x,y=y)
graph.plot(data)
graph.text('This should be placed inside a box',5,0.5)
I had a quick look through the latest GracePlot module source code. It seems that the author has not yet implemented the capability to make boxes.
Normally, the "Box" tool can be found under "Drawing Objects" when using the Grace/xmgrace GUI. Create a box and save the project, then view it in a text editor as the file is saved in an ASCII format. The following section can be found:
#with box
# box on
# box loctype view
# box 0.340196078431, 0.691176470588, 0.619607843137, 0.513725490196
# box linestyle 1
# box linewidth 1.0
# box color 1
# box fill color 1
# box fill pattern 0
#box def
As you can see by comparing similar chunks for text creation etc. with the source code, the GracePlot module is just printing similar commands for each of the things it is generating. It would be quite easy to add the capability to make boxes. Perhaps you have time yourself? :)
The capability for text has been implemented:
from GracePlot import *
p = GracePlot()
[....]
p.text('Hello, world!', 0.5, 0.4, color=violet, charsize=1.2)
will place some violet-colored text at (0.5, 0.4) with 1.2 character size.
Boxes in Grace do not have their own text, so in order to solve your question you can simply place a text object over the box you created.
I'm using wxpython to create GUI with python, now, is there a way to color specific part of the text?
Example (using Tkinter):
http://i.stack.imgur.com/fGAVA.png
Here is my Print function:
def Print(self, String):
''' Print Received Data '''
self.text_serverLog.AppendText(datetime.now().strftime("[%H:%M:%S] " + String + "\n"))
I found the function SetForegroundColour but sadly its color the whole TextCtrl.
I'm using Win7, python 2.7, wxpython.
Thanks.
You can use the wx.TextCtrl in RichText mode by setting its style flag to wx.TE_RICH or wx.TE_RICH2. You can also use the aforementioned RichTextCtrl or the StyledTextCtrl (1 or 2). There's also FancyText, but I think that's more of a helper for drawing text than a real control the user can edit. Regardless, all of these widgets have examples in the wxPython demo package, which you can find at the wxPython website's download page.
I have read a couple of URLs about setting colour in terminal. But after a colour change a while later I'd like to reset into previous colour. How can I get current colour ?
(I'd like to avoid third party libraries and use only batteries included ;-))
Especially (from (python) colour printing with decorator in a function ):
import sys
green = '\033[01;32m'
red = '\033[01;31m'
... remember current colours here ...
sys.stdout.write(green+"Hello ")
sys.stderr.write(red+"world!")
You can return default color the same way you colorize your texts:
native = '\033[m'
sys.stdout.write(native)
Thus temporary coloring may be achieved with
print green + 'Hello' + native