Building basic dialog in Windows?

Fred fred at acme.com
Tue Aug 24 21:05:34 EDT 2004


On Tue, 24 Aug 2004 20:49:29 +0200, Fred <nobody at nowhere.com> wrote:
>OK, I'll check it out. It seems like pywin32 is meant for C++
>developers who are already proficient with MFC, and the only
>documentation is pretty much the scripts that comes with the software,
>but I'll try to figure it out and extract what I need.

After comparing the scripts under \Demo, here's how to display a basic
dialog in Windows with PythonWin/PyWin32, with a label, and two
pushbuttons, OK/Cancel. When you click on OK, the text of the label
changes, and the OK button is disabled:

from pywin.mfc import dialog
import win32con

dlgStatic = 130
dlgButton = 128

class Mydialog(dialog.Dialog):
	def OnInitDialog(self):
		rc = dialog.Dialog.OnInitDialog(self)
		return rc
	
	def OnOK(self):
		label=self.GetDlgItem(dlgStatic)
		label.SetWindowText("Text changed")
		button=self.GetDlgItem(win32con.IDOK)
		button.EnableWindow(0)
		
	def OnCancel(self):
		self.Cancel = 1
		self._obj_.OnCancel()

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
s = win32con.WS_TABSTOP | cs
w = 184
h = 40

dlg = [["PyWin32",(0, 0, w, h),	style,	None,	(8, "MS Sans
Serif")],]

dlg.append([dlgStatic, "Click on OK", dlgStatic, (7, 5, 69, 9), cs |
win32con.SS_LEFT])
dlg.append([dlgButton, "OK", win32con.IDOK, (7, 20, 50, 14), s |
win32con.BS_DEFPUSHBUTTON])
s = win32con.BS_PUSHBUTTON | s
dlg.append([dlgButton, "Cancel", win32con.IDCANCEL, (124, 20, 50, 14),
s])

d = Mydialog(dlg)
d.DoModal()

My .15E/.20$
Fred.



More information about the Python-list mailing list