[Tutor] PyWin32 - Library of functions to interact with windows?

Scott Nelson sirgnip at gmail.com
Wed Oct 14 20:26:00 CEST 2009

If I may chime in...

As Alan said, pywin is basically a thin wrapper around the Win32 API.  The
Win32 API is very complex.  Thus pywin is, by necessity, also very complex.
There is documentation for pywin, but it is very minimal as you've probably
noticed.  If you are a *very* bold beginner with lots of patience, the best
documentation for pywin is actually the documentation for the Win32 API
itself found on Microsoft's "MSDN Library" website [1].  Navigating and
using this documentation requires a knowledge of the Windows architecture
and C programming. Once you find what you want in the MSDN documentation,
you can usually find the same function in pywin.  Again, this is not going
to be easy if you are a beginner (it is difficult even for more experienced
programmers), but I wanted to let you know the info is out there.  If you
want to dive into Win32 programming and learn the basics, the books Alan
mentioned are good.  But again, Win32 programming is pretty low-level
and complex.  There is usually an easier way to do most things you need to
do.  Especially if you want to create GUI's in Python, don't start with
pywin and Win32.  Use EasyGUI, Tkinter, or wxPython (in order of easiest to
most powerful)

Now, back to your specific task.  To clarify, I'm assuming you want to color
the text that shows up in Window's console when you do "print" from Python,
correct?  It *is* possible to color console text with Python and pywin.
But, it is tricky and not obvious.  I've been wondering how to do this
myself and I recently found some C code on the web [2] that does this and I
translated that into to Python and pywin.  It can be done in about 4 lines
of Python.

To get you started, here is the link [3] to the MSDN documentation that
tells you what you need to know about coloring text in a Windows console
window (what Python's print command uses).  Then, it is up to you to
translate this into Python and pywin.  The link [2] could also help.  If you
are up for a challenge, give it a shot.  If you get stuck or it takes too
long, write back and I/we can nudge you in the right direction with a code

(While writing this email, I also discovered that you can control the cursor
position in a win32 console with pywin!  Fun!)

Best of luck, and feel free to ask for more help!


[1] - http://msdn.microsoft.com/en-us/library/default.aspx
[2] - http://www.dreamincode.net/forums/showtopic23272.htm
[3] - http://msdn.microsoft.com/en-us/library/ms682088(VS.85).aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091014/af6c9d85/attachment-0001.htm>

More information about the Tutor mailing list