faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 19 people (84%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I use Windows API in Python? With an example please.

Jul 11th, 2000 04:38
unknown unknown, Neil Hodgson


You should grab Mark Hammond's Win32 extensions from
http://starship.python.net/crew/mhammond/ which includes the Pythonwin 
development environment.
For an example, start Pythonwin, and you should an Interactive Window.
Into that window type (just the bit after ">>>"):
>>> import win32api
    this loads definitions of the core Windows API.
    Then call an API with
>>> win32api.Beep(3000,300)
As you press the "." a list of the available calls should appear. You 
can continue typing or select an item and press Tab to enter that item.
Pressing enter after this typing will execute the code and produce a
noise - hope you have a sound card.
The online help lists all of the APIs wrapped by the Win32 extensions 
which includes a good proportion of the entire Win32 API. For complete 
descriptions of each API, you will want access to MSDN, either online at 
http://msdn.microsoft.com or by downloading the Platform SDK from the 
same site. There is a book by Mark and Andy called "Python Programming 
on Win32" which contains a lot of pages and a decent cover illustration.