[Tutor] pywin DoModal vs CreateWindow

Ben nebpro at gmail.com
Wed Mar 21 18:42:25 CET 2007

Recently my friend ask me for help on pywin32 gui programming. There is one
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. If we run the
program from command prompt, the gui won't stay in loop (or basically just
blink for a moment and disappear). It is different if we run the program
from "PythonWin" program. Can someone explain this for us? It cause a lot of
confusion. And what should we do to make the gui stay in loop if we used
"CreateWindow" and called it from command prompt. We really appreciate for
any help. Thanks in advance.

Below is the snippet code that we used for testing:
Note: Codes credits to Mark Hammond.

import win32ui
import win32con
from pywin.mfc.dialog import Dialog

d = Dialog (win32ui.IDD_SIMPLE_INPUT)

print d
print d._obj_

d.CreateWindow ()
#d.ShowWindow (win32con.SW_SHOWNORMAL)
button = d.GetDlgItem (win32ui.IDC_PROMPT1)
print "button: ", button
button.SetWindowText ("Hello from Python")
d.SetWindowText ("Python is awesome")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070321/5a994fa0/attachment.html 

More information about the Tutor mailing list