Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Python color text and splash screen

Posted on 2007-11-24
4
Medium Priority
?
3,261 Views
Last Modified: 2012-08-14
I am working on a telnet python BBS and have ran into two problems.

The first one is, I can not find any way to have the server print something in color on the client's screen like having the line:

self.conn.send("Name? ")

print "Name?" in red or having the line:

print "Handling message: ",msg

print "Handling Message: Message" come up green.

The second problem I am having is the splash screen print. The only way I know how to handle the splash screen is like the following:


self.conn.send("                                         .__            ")
self.conn.send("      ____ ___  ________    _____ ______ |  |   ____    ")
self.conn.send("    _/ __ \\  \/  /\__  \  /     \\____ \|  | _/ __ \   ")
self.conn.send("    \  ___/ >    <  / __ \|  Y Y  \  |_> >  |_\  ___/   ")
self.conn.send("     \___  >__/\_ \(____  /__|_|  /   __/|____/\___  >  ")
self.conn.send("         \/      \/     \/      \/|__|             \/   ")

But that always seems to error. (I know the last part does not look very good so you might want to past it into note pad to view it).
0
Comment
Question by:ZoeticNepenthe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 29

Expert Comment

by:pepr
ID: 20344191
It is not clear what OS do you use. Anyway, if console is responsible for displaying the coloured text at the client side and server sends the text, then also the colour attributes must be sent somehow from the server.

The curses module may be the answer for you (http://docs.python.org/lib/module-curses.html). See "Curses Programming with Python" by A.M. Kuchling and Eric S. Raymond (http://www.amk.ca/python/howto/curses/curses.html). Focus on parts "4 Displaying Text" and "4.1 Attributes and Color".
0
 
LVL 1

Accepted Solution

by:
ZoeticNepenthe earned 0 total points
ID: 20363036
I found my own solution here but thinks pepr.

To print color text this works:

print '\033[1;31mSome Red Text\033[0m'
print '\033[1;32mSome Green Text\033[0m'
print '\033[1;33mSome Yellow text\033[0m'
print '\033[1;34mSome Blue Text\033[0m'

http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html has other information on the color codes.

self.conn.send("                                         .__            ")
self.conn.send("      ____ ___  ________    _____ ______ |  |   ____    ")
self.conn.send("    _/ __ \\  \/  /\__  \  /     \\____ \|  | _/ __ \   ")
self.conn.send("    \  ___/ >    <  / __ \|  Y Y  \  |_> >  |_\  ___/   ")
self.conn.send("     \___  >__/\_ \(____  /__|_|  /   __/|____/\___  >  ")
self.conn.send("         \/      \/     \/      \/|__|             \/   ")

should have been

self.conn.send("                                         .__            \r\n")
self.conn.send("      ____ ___  ________    _____ ______ |  |   ____    \r\n")
self.conn.send("    _/ __ \\  \/  /\__  \  /     \\____ \|  | _/ __ \   \r\n")
self.conn.send("    \  ___/ >    <  / __ \|  Y Y  \  |_> >  |_\  ___/   \r\n")
self.conn.send("     \___  >__/\_ \(____  /__|_|  /   __/|____/\___  >  \r\n")
self.conn.send("         \/      \/     \/      \/|__|             \/   \r\n")

I just needed the "\r\n" command at the end.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20412425
Closed, 250 points refunded.
modus_operandi
EE Moderator
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question