Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 11th, 2007, 1:19 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Different Colors In Console Output

Quote:
Originally Posted by vBulletin Notice
Hello Sane it appears that you have not posted on our forums in several weeks, why not take a few moments to ask a question, help provide a solution or just engage in a conversation with another member in any one of our forums?
lol...

I am running Python 2.4 on Windows. How can I display console output in a different color?

All the solutions I find are Unix only.

I know how to do it in C, but not Python. So I know it must be possible. If it isn't, I'll just use wxWidgets.

Thanks for any help.
Sane is offline   Reply With Quote
Old Feb 11th, 2007, 8:56 PM   #2
MicDareall
Programmer
 
Join Date: Dec 2005
Posts: 67
Rep Power: 0 MicDareall is an unknown quantity at this point
Have you downloaded the win32 api extensions for python? Im not positive this is it because I haven't downloaded it in a while but after a quick google I think this is it.

https://sourceforge.net/project/show...group_id=78018
MicDareall is offline   Reply With Quote
Old Feb 12th, 2007, 2:51 PM   #3
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Nice to see you back:
[PHP]# change color in the console display (Windows)
# color is a two digit hexadecimal number
# the first digit is the background
# the second digit is the foreground (text)
# 0=black 1=blue 2=green ... to E=yellow F=white
import os
os.system("color F2") # green(2) text on white(F) background[/PHP]BTW, don't take DaWei serious, he is crude to most of us!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Feb 12th, 2007, 6:09 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
@MicDareall:
Yes, I have.
@Dietrich:
Oh cool! The 16 color system! Brings back memories of Q-BASIC.

Thanks a bunch!!

I'm confused. Did DaWei post, then delete it? Also, I know of DaWei's habits. I've been a member here as long as you. :p

EDIT : Oh... there's a problem. This changes the font and background color everywhere. I needed this so that I could identify importance of certain labels in the output. In other words, I need to be able to change the color for only a specific line (or word).

Last edited by Sane; Feb 12th, 2007 at 6:22 PM.
Sane is offline   Reply With Quote
Old Feb 12th, 2007, 8:52 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
No, I didn't make a post here. People just like to take arbitrary shots at me. I haven't lost as much as one second of sleep over it. The caliber of the detractors is too low. Glad to see you back, Sane.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 13th, 2007, 12:54 AM   #6
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Sorry Sane, that's just ye olde DOS command. Looks like you ought to use wxPython then.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Feb 13th, 2007, 8:54 PM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Wow. Are you sure? I've seen in a console window, on Windows, different colors for different lines before. It was written in C.
Sane is offline   Reply With Quote
Old Feb 14th, 2007, 12:06 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Sure, you can write it in C/C++, for Windows. See the Console part of the API. If you want, I can pop you some code, but I thought you wanted to do it in Python, and I haven't researched that. A lot of people say "DOS" when they shouldn't (it's an acronym for Disk Operating System). It means nothing. It could be MSDOS or another OS or the Windows Command facility or the Windows CMD facility or any number of other things.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 15th, 2007, 12:19 AM   #9
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Quote:
Originally Posted by Sane View Post
Wow. Are you sure? I've seen in a console window, on Windows, different colors for different lines before. It was written in C.
You mean this old thing:
#include <stdio.h>
#include <windows.h> 

int main(void)
{
  HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  WORD wAttributes; 
  CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo ; 
  
  // save current text and backgroud colors
  GetConsoleScreenBufferInfo(hConsoleOutput, &lpConsoleScreenBufferInfo);
  wAttributes = lpConsoleScreenBufferInfo.wAttributes; 
  
  // set new text and background colors
  SetConsoleTextAttribute(hConsoleOutput, FOREGROUND_RED | FOREGROUND_INTENSITY);
  
  printf("Hello World! in colorful C\n");

  // restore origional text and background colors
  SetConsoleTextAttribute(hConsoleOutput, wAttributes);
  
  getchar();  // wait
  return 0;
}
Sure, you can use the Windows API functions in Python. Just get the Win32 extension package.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Feb 19th, 2007, 6:23 PM   #10
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Aahh... so those are the win32api functions "MicDareall" was mentioning.

I haven't tried it, but I'm sure it'll work great. Thanks!
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Manipulating the console using Windows API rup C++ 2 Nov 17th, 2006 1:04 PM
Change the name of output file jazz C 4 Jun 28th, 2006 2:54 AM
Redirecting Console Output Sane Python 3 Jun 1st, 2006 4:56 PM
The Black Art of Video Game Console Design lostcauz Book Reviews 0 Apr 26th, 2006 7:31 PM
console output matko C++ 10 Sep 26th, 2005 2:14 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC