How to change easyGUI python text color - python

I want to change the text color of msgbox, ynbox and the output text in easyGUI.
Please help!

Quoting from this site:
EasyGUI won;t help change colour, it is just a way of making
a command line script act like a GUI - by popping up dialog
boxes to capture input and dsplay messages. It replaces
raw_input and print with dialogs.
--------code--------
from WConio import textcolor
apples_left = 5
print "There are",(textcolor(4)),apples_left,(textcolor(7)),"left in the basket."
The output works, but there is one snag. I think that I am leaving
something out because it has the word "None" on both sides of the
variable.
This could be an easy solution for your problem.
You may get WConio from here:
http://newcenturycomputers.net/projects/wconio.html
If you face python not found error at the time of installation then you may try following this answer.
UPDATE:
There is one more package named Colorama, which is cross-platform for colored terminal text and pretty much stable. You may give it a try as well.

Related

How to change color of the terminal using Python

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:
[]

In SikuliX, type(variable) always types the variable then presses enter automatically. How do I avoid pressing enter?

Sorry if this is really basic, I cannot find a workaround. I have a variable called doc that stores the number 510 that was copied from an excel cell.
I need to type it in a field, but I need to continue typing in another field on the same page afterwards.
My code has:
type(doc)
The log shows:
[log] TYPE "510#ENTER."
The full code looks like this:
type(doc)
wait(1)
type(Key.DOWN)
type(Key.BACKSPACE+Key.BACKSPACE+Key.BACKSPACE+Key.BACKSPACE)
wait(1)
type(code)
However, I can't get to the type(code) because it switches page before I get there...
Using paste() maybe solved your issue here but this is not the right way to do that as Sikuli does not automatically presses any buttons.
Your problem is probably with the doc variable itself. In your case, you probably just copied the new line character with your variable from excel and that's why Sikuli is hitting Enter. To avoid that, try stripping the new line from your variable prior to typing it, like this:
doc.rstrip()
Then do your usual type(doc) and it should be fine.
Another thing that works is: doc.strip()
It turns out sikuli writes /n after strings, so strip removes that /n.

Having trouble playing music using IPython

I have the lines of code
import IPython
IPython.display.Audio(url="http://www.1happybirthday.com/PlaySong/Anna",embed=True,autoplay=True)
And I'm not really sure what's wrong. I am using try.jupyter.org to run my code, and this is within if statements. The notebook is also taking in user inputs and printing outputs. It gives no error, but just doesn't show up/start playing. I'm not really sure what's wrong.
Any help would be appreciated. Thanks!
First you should try it without the if statement. Just the two lines you mention above. This will still not work, because your URL does point to an HTML page instead of a sound file. In your case the correct URL would be 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'.
The Audio object which you are creating, will only be displayed if it is the last statement in a notebook cell. See my Python intro for details. If you want to use it within an if clause, you can use IPython.display.display() like this:
url = 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'
if 3 < 5:
IPython.display.display(IPython.display.Audio(url=url, autoplay=True))
else:
print('Hello!')

Python Reportlab combine paragraph

I hope you can help me trying to combine a paragraph, my style is called "cursiva" and works perfectly also I have other's but it's the same if I change cursiva to other one. the issue is that If I use this coude o get this.
As you can see guys it shows with a line break and I need it shows togetter.
The problem is that i need to make it like this (one, one) togetter because I need to use two styles, the issue here is that I'm using arial narrrow so if I use italic or bold I need to use each one by separate because the typography does not alow me to use "< i >italic text< /i > ", so I need to use two different styles that actually works fine by separate.
how can I achive this?
cursiva = ParagraphStyle('cursiva')
cursiva.fontSize = 8
cursiva.fontName= "Arialni"
incertidumbre=[]
incertidumbre.extend([Paragraph("one", cursiva), Paragraph("one", cursiva)])
Thank you guys
The question you are asking is actually caused by a workaround for a different problem, namely that you don't know how to register font families in Reportlab. Because that is what is needed to make <i> and <b> work.
So you probably already managed to add a custom font, so the first part should look familiar, the final line is probably the missing link. It is registering the combination of these fonts a family.
from reportlab.pdfbase.pdfmetrics import registerFontFamily
pdfmetrics.registerFont(TTFont('Arialn', 'Arialn.ttf'))
pdfmetrics.registerFont(TTFont('Arialnb', 'Arialnb.ttf'))
pdfmetrics.registerFont(TTFont('Arialni', 'Arialni.ttf'))
pdfmetrics.registerFont(TTFont('Arialnbi', 'Arialnbi.ttf'))
registerFontFamily('Arialn',normal='Arialn',bold='Arialnb',italic='Arialni',boldItalic='Arialnbi')

Python Terminal Menu? Terminal Coloring? Terminal progress display?

I have a project that uses Python (2.* flavors) extensively and I am wondering if there is a terminal menu library or something to that effect? I am looking to breathe some flavor and life into my script by simplifying some of the options using arrow key highlightable options, some color, etc etc. I vaguely recall there being a way to make a bash shell terminal menu but I'm not at all sure how I would pass user input from bash to the python script, perhaps have a bash terminal menu push the script call with sysarggs? I'd like something on the python side if possible. Any suggestions?
Also just a random question, kind of fits in here since we're on the topic of terminal aesthetics, what's the best way to handle a counter? My script looks for image files, then when it finds one it clears the terminal with a subprocess call to clear and then prints the total images found again IE 10 images, find one, clear, print "11 images found", sometimes my script works REAL fast and I feel this detriments performance. Thoughts?
Thanks so much everyone, I love stack overflow ;)
Edit - Thanks for all the quick responses! I have alot of options to mull over. I gave everyone an upvote because all of your responses are helpful. I will check out all the libraries when I get home and try to pick one of you for an answer depending on what hashes out the best, wish I could pick you all though because all of your answers are relevant! Much appreciated folks. I'll report back in once I get home from work and get a chance to get some coding in ;)
Edit 2 - A clarification on the counter/progress display, looking for a way to keep this from detrimenting performance when my script finds thousands of images in a very short ammount of time, this is real chopped up python...
for each item in list:
if item ends with .jpg
cnt=cnt+1
do stuff with image file
subprocess.call('clear')
print str(cnt)+" total images processed."
Thanks again!
Check out Clint (*C*ommand *L*ine *IN*terface *T*ools)!
Official page: https://github.com/kennethreitz/clint
Great overview: http://www.nicosphere.net/clint-command-line-library-for-python/
Example colors:
from clint.textui import colored
print 'I love ' + colored.yellow('pyt') + colored.blue('hon')
and indents too:
from clint.textui import colored, indent, puts
with indent(3, quote=colored.red(' >')):
puts ('some random text')
puts ('another text')
with indent(3, quote=colored.green(' |')):
puts('some more nested identation')
puts('cool isn\'t?')
P.S. The same author wrote a similarly nice HTTP request library called "requests": https://github.com/kennethreitz/requests
If you want a lot of control and you're on *nix, you could use the stdlib curses module.
If you just want a bit of color (/don't want to modify your script a ton to fit curses), you can use ANSI escape codes. For example:
print '\033[1;32mgreen\033[1;m'
will print the word 'green' colored... green.
Here's a loading bar I came up with using carriage returns (based on the answers in this forum):
from time import sleep
import sys
num = 100
print 'Loading: [%s] %d%%' % (' '*(num/2), 0),
try:
colorCode = 43
for x in xrange(num+1):
if x == num: colorCode = 42
print '\rLoading: [\033[1;%dm%s\033[1;m%s] %d%%' % (colorCode, "|"*(x/2), " "*(num/2-x/2), x),
sys.stdout.flush()
sleep(0.02) # do actual stuff here instead
except KeyboardInterrupt:
print '\rLoading: [\033[1;41m%s\033[1;m%s] %d%% ' % ("|"*(x/2), " "*(num/2-x/2), x)
Example Output:
Loading: [||||||||||||||||||||||||||||||||||||||||| ] 82%
(Although it doesn't show up on SO, it is colored- yellow for loading, red for abort, and green for done.)
There's a library called Urwid that offers menus and some more. I never used it for serious purposes, but the it work pretty fine with my preliminary experiences on it. It works on Un*x systems only though. (The project page says it works under Cygwin, but I never tried.)

Categories