![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Different Colors In Console Output
Quote:
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. |
|
|
|
|
|
|
#2 |
|
Programmer
Join Date: Dec 2005
Posts: 67
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
@MicDareall:
Yes, I have.@Dietrich: Oh cool! The 16 color system! Brings back memories of Q-BASIC.
__________________
Waterloo's Canadian Computing Competition (CCC) - Stage 2 Problems, Solutions, and Test Data Last edited by Sane; Feb 12th, 2007 at 6:22 PM. |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Sorry Sane, that's just ye olde DOS command. Looks like you ought to use wxPython then.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Wow. Are you sure? I've seen in a console window, on Windows, different colors for different lines before. It was written in C.
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#9 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
#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;
}
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Aahh... so those are the win32api functions "MicDareall" was mentioning.
I haven't tried it, but I'm sure it'll work great. Thanks! ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |