[Tutor] pywin DoModal vs CreateWindow

Alan Gauld alan.gauld at btinternet.com
Thu Mar 22 00:45:27 CET 2007


"Ben" <nebpro at gmail.com> wrote

> Recently my friend ask me for help on pywin32 gui programming.

pywin32 is only really a sensible route if you already know MFC
and want to translate some design into Python. Otherwise its
painful. Mainlybecause the underlying windows code is painful.
It is full of ambiguous calls that apprar to do the same thing,
but not quite...

> thing that throw us off (Note. Both of us don't have any mfc 
> background and
> we are newbie in python). When the "DoModal" is called, the gui will 
> stay in
> loop. It is different when the "CreateWindow" is called.

I'm not quite sure what you mean by stay in loop.
Do Modal brings up a modal window (like the Find/replace dialog
in a word processor) which runs in a separate thread.
CreateWindow is usually used to create windows or widgets
in the main thread. ie it creates the main window or widgets
within it)

> program from command prompt,

Don't try MFCV GUI programming from the Python
command prompt >>>. It is likely to cause confusion
between the python interpreter(a windows program),
the DOS command box(a windows program) and
your program(a windows program!) To have 3 windows
programs running in the same screen space is not
a happy experioence for you or the OS.

> blink for a moment and disappear). It is different if we run the 
> program
> from "PythonWin" program. Can someone explain this for us?

Nope, it depends on too many things. But basically Pythonwin
tries to catch most things that can go wrong and turn them into
messages on screen. Most times it works, other times it won't.
But its slightly more reliable that a >>> prompt in a DOS box
for MFC work. But i'd still recommend the old fashioned way
of just using a text editor(maybe Pythonwin) and then running
your program from the dos prompt directly.

HTH,

Alan G. 




More information about the Tutor mailing list