目前,Boa Constructor 的稳定版本为0.4.4,在python 2.4.x环境下运行正常,但在python 2.5下运行python boa.py时出现了下面的错误:
'module' object has no attribute 'NotebookSizer'
这是因为该版本与python 2.5之间不兼容。下面介绍安装最新开发版本的方法:
首先下载TortoiseCVS 最新版安装,这是一个CVS版本控制软件,下面将用来下载Boa开发版本文件。在适当的目录下新建一个文件夹,打开后在其中点击鼠标右键,选择CVS-->preferences.. 修改language为Chinese(simplified) [GB2312]。然后重新点击鼠标右键,选择CVS 取出.. ,在弹出的对话框中做如下配置:
单击确认后开始下载文件。根据网速情况,大概10分钟后下载完成。
用Boa完成的一个简单的例子:
App1.py:
-
#!/usr/bin/env python
-
#Boa:App:BoaApp
-
-
import wx
-
-
import Frame1
-
-
modules ={'Frame1': [1, 'Main frame of Application', u'Frame1.py']}
-
-
class BoaApp(wx.App):
-
def OnInit(self):
-
self.main = Frame1.create(None)
-
self.main.Show()
-
self.SetTopWindow(self.main)
-
return True
-
-
def main():
-
application = BoaApp(0)
-
application.MainLoop()
-
-
if __name__ == '__main__':
-
main()
-
Frame1.py:
-
#Boa:Frame:Frame1
-
-
import wx
-
-
def create(parent):
-
return Frame1(parent)
-
-
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1PANEL1,
-
] = [wx.NewId() for _init_ctrls in range(4)]
-
-
class Frame1(wx.Frame):
-
def _init_ctrls(self, prnt):
-
# generated method, don't edit
-
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
-
pos=wx.Point(495, 302), size=wx.Size(220, 106),
-
style=wx.DEFAULT_FRAME_STYLE, title=u'\u5173\u4e8e..')
-
self.SetClientSize(wx.Size(212, 79))
-
-
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
-
pos=wx.Point(0, 0), size=wx.Size(212, 79),
-
style=wx.TAB_TRAVERSAL)
-
-
self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'\u5173\u4e8e..',
-
name='button1', parent=self.panel1, pos=wx.Point(40, 40),
-
size=wx.Size(56, 24), style=0)
-
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
-
id=wxID_FRAME1BUTTON1)
-
-
self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label=u'\u9000\u51fa',
-
name='button2', parent=self.panel1, pos=wx.Point(128, 40),
-
size=wx.Size(48, 24), style=0)
-
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
-
id=wxID_FRAME1BUTTON2)
-
-
def __init__(self, parent):
-
self._init_ctrls(parent)
-
-
def OnButton1Button(self, event):
-
info = wx.AboutDialogInfo()
-
info.Name = "Hello World"
-
info.Version = "1.0.0"
-
info.Copyright = "(C) 2007 viechang"
-
wx.AboutBox(info)
-
-
def OnButton2Button(self, event):
-
self.Close(True)
-
一个运行结果如下:
该程序在windowsXp + python2.5 + wxpython2.8.3.0 + Boa Constructor 0.5.2 下测试通过。
附:回复求教者留言
完全可以,使用wx库就行
例如:
-
-
import wx
-
-
#----------------------------------------------------------------------
-
-
class RichTextFrame(wx.Frame):
-
def __init__(self, *args, **kw):
-
wx.Frame.__init__(self, *args, **kw)
-
-
def OnFileOpen(self, evt):
-
# This gives us a string suitable for the file dialog based on
-
# the file handlers that are loaded
-
wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
-
dlg = wx.FileDialog(self, "Choose a filename",
-
wildcard=wildcard,
-
style=wx.OPEN)
-
if dlg.ShowModal() == wx.ID_OK:
-
path = dlg.GetPath()
-
if path:
-
fileType = types[dlg.GetFilterIndex()]
-
self.rtc.LoadFile(path, fileType)
-
dlg.Destroy()
-
-