[Tutor] Pythonwin Question

Magnus Lycka magnus@thinkware.se
Mon, 30 Sep 2002 12:18:28 +0200


At 05:12 2002-09-30 -0400, Jmllr891@cs.com wrote:
>I recently decided to check out Pythonwin just to see what it was like. I 
>found the page for it on the Python web site and was quite amused. It says 
>that Pythonwin is a wrapper for the MFC library.
>
>Where can I get the MFC library? And second of all (since we're talking 
>about Microsoft), how much would it (the MFC library) or a product that it 
>comes with cost?

Well, it depends on what version of Windows you want to
buy. I dunno, Win ME is about $70 I guess, and the more
stable versions cost a few hundred? But I guess you have
Windows already...and with it a file called mfc42.dll or
something like that. ;)

So, MS Windows and ActiveState Python, or standard python
with the win32-all package is all you need. At least with
ActiveState Python, there is a bunch of docs included.
You reach it from the PythonWin help menu.

Another source if information is the excellent book
Python Programming on Win 32, see
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonProgrammingOnWinThirtyTwo
or
http://www.ora.com/catalog/pythonwin32/
Note the sample chapters and examples. There is some info
of relevance in
http://www.oreilly.com/catalog/pythonwin32/chapter/ch20.html

The obvious limitation with MFC is that it only runs
on Windows. It's also much less used (I think) than
Tkinter and wxPython. (Although, it you use Tkinter
or wxPython you'll get into trouble if you try to run
your GUI programs from within PythonWin, since you get
two event loops inside each other, and they don't get
along...)

In PythonWin you can do stuff like this do play with
MFC:

 >>> import win32ui
 >>> from pywin.mfc.dialog import Dialog
 >>> d=Dialog(win32ui.IDD_SIMPLE_INPUT)
 >>> d.CreateWindow()
 >>> button=d.GetDlgItem(win32ui.IDC_PROMPT1)
 >>> button.SetWindowText("Hello from Python")

You can also use COM and other things, so you can
perform magic with Word and Excel etc.

Have fun!


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se