Python and Windows.Forms
Larry Bates
lbates at swamisoft.com
Thu May 13 16:51:51 EDT 2004
Shane,
You can access all the Windows common dialogs (forms?)
Python by using Win32 extensions. Specifically using
pywin.mfc dialog and win32ui modules. Here is an example
that I "hacked" from Demos directory. If this is
something you want to study more see Mark Hammond's
excellent Python Programming on Win32 book.
HTH,
Larry Bates
Syscon, Inc.
#
# Progress bar control example
#
# PyCProgressCtrl encapsulates the MFC CProgressCtrl class. To use it,
# you:
#
# - Create the control with win32ui.CreateProgressCtrl()
# - Create the control window with PyCProgressCtrl.CreateWindow()
# - Initialize the range if you want it to be other than (0, 100) using
# PyCProgressCtrl.SetRange()
# - Either:
# - Set the step size with PyCProgressCtrl.SetStep(), and
# - Increment using PyCProgressCtrl.StepIt()
# or:
# - Set the amount completed using PyCProgressCtrl.SetPos()
#
# Example and progress bar code courtesy of KDL Technologies, Ltd., Hong
Kong SAR, China.
#
from pywin.mfc import dialog
import win32ui
import win32con
import time
def MakeDlgTemplate():
style = (win32con.DS_MODALFRAME |
win32con.WS_POPUP |
win32con.WS_VISIBLE |
win32con.WS_CAPTION |
win32con.WS_SYSMENU |
win32con.DS_SETFONT)
cs = (win32con.WS_CHILD |
win32con.WS_VISIBLE)
w = 215
h = 36
dlg = [["Progress bar",
(0, 0, w, h),
style,
None,
(8, "MS Sans Serif")],
]
return dlg
class TestDialog(dialog.Dialog):
def OnInitDialog(self):
rc = dialog.Dialog.OnInitDialog(self)
self.pbar = win32ui.CreateProgressCtrl()
self.pbar.CreateWindow (win32con.WS_CHILD |
win32con.WS_VISIBLE,
(10, 10, 310, 24),
self, 1001)
return rc
def demo():
d = TestDialog (MakeDlgTemplate())
d.CreateWindow ()
for i in xrange(100):
d.pbar.SetPos(i)
time.sleep(0.1)
d.OnCancel()
if __name__=='__main__':
demo()
# $Header: /home/cvsroot/PyWin32/Pythonwin/pywin/Demos/progressbar.py,v 1.1
1999/09/01 23:33:35 mhammond Exp $
"Shane" <s.brennan at cox.net> wrote in message
news:sTAoc.67180$sK3.3272 at nwrddc03.gnilink.net...
> Hey folks,
>
> I'm new to Python and programming in general and I'm having a blast. I
> was curious if it was possible to use Windows.Forms; I'm interesting in
> porting a C++ program a friend wrote for me to Python and would like to
> use a similar GUI (its fairly simple). I've noticed ActiveState has a
> .NET plugin for Python...
>
> http://www.activestate.com/Products/Visual_Python/?_x=1
>
> ...but I'm not sure that is what I am looking for and I'm stuck with
> Borland C# Builder Personal Edition anyway for financial reasons.
>
> One thing that threw me for a loop was that when I used ActivePython
> (ActiveStates Python IDE, I like it so far) to run a script I wrote, it
> gives me a Windows.Forms input box when I call raw_input as opposed to
> the regular console input message you get in the basic interactive
> window that comes with a standalone Pythin installation. What's going on
> there? Can I harness that a little more?
>
> Shane Brennan
More information about the Python-list
mailing list