最近需要做点支持linux的跨平台gui,网上查到了wxPython及Boa,感觉不错,照着Boa文档做做练习。

代码:

App:

 #!/usr/bin/env python
#Boa:App:BoaApp import wx import Frame1 modules ={'Dialog1': [0, '', u'Dialog1.py'],
'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()

Dialog:

 #Boa:Dialog:Dialog1

 import wx

 def create(parent):
return Dialog1(parent) [wxID_DIALOG1, wxID_DIALOG1BUTTON1, wxID_DIALOG1STATICBITMAP1,
wxID_DIALOG1STATICTEXT1, wxID_DIALOG1STATICTEXT2,
] = [wx.NewId() for _init_ctrls in range(5)] class Dialog1(wx.Dialog):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_DIALOG1, name=u'Dialog1', parent=prnt,
pos=wx.Point(365, 232), size=wx.Size(400, 492),
style=wx.DEFAULT_DIALOG_STYLE, title=u'About Notebook')
self.SetClientSize(wx.Size(392, 465)) self.staticText1 = wx.StaticText(id=wxID_DIALOG1STATICTEXT1,
label=u'Note Book - Simple Text Editor', name='staticText1',
parent=self, pos=wx.Point(72, 32), size=wx.Size(220, 19),
style=wx.ALIGN_CENTRE)
self.staticText1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
False, u'Tahoma')) self.staticText2 = wx.StaticText(id=wxID_DIALOG1STATICTEXT2,
label=u'This is my first Boa app.', name='staticText2',
parent=self, pos=wx.Point(112, 96), size=wx.Size(129, 14),
style=0)
self.staticText2.SetBackgroundColour(wx.Colour(212, 208, 200)) self.staticBitmap1 = wx.StaticBitmap(bitmap=wx.Bitmap(u'F:/Projects/guide1/6773383_753857.jpg',
wx.BITMAP_TYPE_JPEG), id=wxID_DIALOG1STATICBITMAP1,
name='staticBitmap1', parent=self, pos=wx.Point(48, 152),
size=wx.Size(280, 160), style=0) self.button1 = wx.Button(id=wxID_DIALOG1BUTTON1, label=u'Close',
name='button1', parent=self, pos=wx.Point(152, 328),
size=wx.Size(75, 24), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_DIALOG1BUTTON1) def __init__(self, parent):
self._init_ctrls(parent) def OnButton1Button(self, event):
self.Close()

Frame:

 #Boa:Frame:Frame1

 import wx
import Dialog1 def create(parent):
return Frame1(parent) [wxID_FRAME1, wxID_FRAME1STATUSBAR1, wxID_FRAME1TEXTEDITOR,
] = [wx.NewId() for _init_ctrls in range(3)] [wxID_FRAME1MENUFILECLOSE, wxID_FRAME1MENUFILEEXIT, wxID_FRAME1MENUFILEOPEN,
wxID_FRAME1MENUFILESAVE, wxID_FRAME1MENUFILESAVEAS,
] = [wx.NewId() for _init_coll_menuFile_Items in range(5)] [wxID_FRAME1MENUHELPABOUT] = [wx.NewId() for _init_coll_menuHelp_Items in range(1)] class Frame1(wx.Frame):
def _init_coll_menuBar1_Menus(self, parent):
# generated method, don't edit parent.Append(menu=self.menuFile, title=u'File')
parent.Append(menu=self.menuHelp, title=u'Help') def _init_coll_menuHelp_Items(self, parent):
# generated method, don't edit parent.Append(help=u'Display Info', id=wxID_FRAME1MENUHELPABOUT,
kind=wx.ITEM_NORMAL, text=u'About')
self.Bind(wx.EVT_MENU, self.OnMenuHelpAboutMenu,
id=wxID_FRAME1MENUHELPABOUT) def _init_coll_menuFile_Items(self, parent):
# generated method, don't edit parent.Append(help='', id=wxID_FRAME1MENUFILEOPEN, kind=wx.ITEM_NORMAL,
text=u'Open')
parent.Append(help='', id=wxID_FRAME1MENUFILESAVE, kind=wx.ITEM_NORMAL,
text=u'Save')
parent.Append(help='', id=wxID_FRAME1MENUFILESAVEAS,
kind=wx.ITEM_NORMAL, text=u'Save As')
parent.Append(help='', id=wxID_FRAME1MENUFILECLOSE, kind=wx.ITEM_NORMAL,
text=u'Close')
parent.Append(help='', id=wxID_FRAME1MENUFILEEXIT, kind=wx.ITEM_NORMAL,
text=u'Exit')
self.Bind(wx.EVT_MENU, self.OnMenuFileOpenMenu,
id=wxID_FRAME1MENUFILEOPEN)
self.Bind(wx.EVT_MENU, self.OnMenuFileSaveMenu,
id=wxID_FRAME1MENUFILESAVE)
self.Bind(wx.EVT_MENU, self.OnMenuFileSaveasMenu,
id=wxID_FRAME1MENUFILESAVEAS)
self.Bind(wx.EVT_MENU, self.OnMenuFileCloseMenu,
id=wxID_FRAME1MENUFILECLOSE)
self.Bind(wx.EVT_MENU, self.OnMenuFileExitMenu,
id=wxID_FRAME1MENUFILEEXIT) def _init_coll_statusBar1_Fields(self, parent):
# generated method, don't edit
parent.SetFieldsCount(1) parent.SetStatusText(number=0, text=u'status') parent.SetStatusWidths([-1]) def _init_utils(self):
# generated method, don't edit
self.menuFile = wx.Menu(title=u'File') self.menuHelp = wx.Menu(title=u'Help') self.menuBar1 = wx.MenuBar() self._init_coll_menuFile_Items(self.menuFile)
self._init_coll_menuHelp_Items(self.menuHelp)
self._init_coll_menuBar1_Menus(self.menuBar1) def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(550, 227), size=wx.Size(400, 492),
style=wx.DEFAULT_FRAME_STYLE, title=u'Notebook')
self._init_utils()
self.SetClientSize(wx.Size(392, 465))
self.SetToolTipString(u'Frame1')
self.SetWindowVariant(wx.WINDOW_VARIANT_LARGE)
self.SetMenuBar(self.menuBar1) self.statusBar1 = wx.StatusBar(id=wxID_FRAME1STATUSBAR1,
name='statusBar1', parent=self, style=0)
self._init_coll_statusBar1_Fields(self.statusBar1)
self.SetStatusBar(self.statusBar1) self.textEditor = wx.TextCtrl(id=wxID_FRAME1TEXTEDITOR,
name=u'textEditor', parent=self, pos=wx.Point(0, 0),
size=wx.Size(392, 426), style=wx.TE_MULTILINE, value=u'') def __init__(self, parent):
self._init_ctrls(parent)
self.FileName = None def OnMenuFileOpenMenu(self, event):
dlg = wx.FileDialog(self, 'Choose a file', '.', '', '*.*', wx.OPEN)
try:
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
# Your code
self.textEditor.LoadFile(filename)
self.FileName = filename
self.SetTitle(('Notebook - %s') % filename)
finally:
dlg.Destroy() def OnMenuFileSaveMenu(self, event):
if self.FileName == None:
return self.OnFileSaveasMenu(event)
else:
self.textEditor.SaveFile(self.FileName) def OnMenuFileCloseMenu(self, event):
self.FileName = None
self.textEditor.clear()
self.SetTitle('Notebook') def OnMenuFileExitMenu(self, event):
self.Close() def OnMenuHelpAboutMenu(self, event):
dlg = Dialog1.Dialog1(self)
try:
dlg.ShowModal()
finally:
dlg.Destroy() def OnMenuFileSaveasMenu(self, event):
dlg = wx.FileDialog(self, 'Save file as', '.', '', '*.*', wx.SAVE)
try:
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
# Your code
self.textEditor.SaveFile(filename)
self.FileName = filename
self.SetTitle(('Notebook - %s') % filename)
finally:
dlg.Destroy()

运行结果图:

wxPython + Boa 练习程序的更多相关文章

  1. wxPython+Boa Constructor环境配置

    配置之前先完成eclipse + Pydev的配置环境.详见http://www.cnblogs.com/dflower/archive/2010/05/13/1734522.html 1. 安装 w ...

  2. 教程和工具--用wxPython编写GUI程序的

    wxPython是个很好的GUI库,对底层的C++库进行了封装,调用起来很方便,尤其是操作前台UI界面和后台多线程,两者配合很方便,做GUI程序最难是写界面尤其是布局. 关于wxPython,自己正在 ...

  3. Boa练习程序2

    做一个地址簿的gui. #Boa:Frame:AddressEntry import wx def create(parent): return AddressEntry(parent) [wxID_ ...

  4. boa cgi程序cgi_header: unable to find LFLF

    ftp必须用二进制模式上传才可以 sqlite3 arm-linux-gcc hello.c -o hello.cgi -I /cgi/include -L /cgi/lib -static -lsq ...

  5. 介绍Python程序员常用的IDE和其它开发工具

    概述 “工欲善其事,必先利其器”,如果说编程是程序员的手艺,那么IDE就是程序员的吃饭家伙了. IDE 的全称是Integration Development Environment(集成开发环境), ...

  6. Python程序员常用的IDE和其它开发工具

    概述 “工欲善其事,必先利其器”,如果说编程是程序员的手艺,那么IDE就是程序员的吃饭家伙了. IDE的全称是Integration Development Environment(集成开发环境),一 ...

  7. wxPython学习笔记(一)

    创建最小的空的wxPython程序 frame = wx.Frame(parent=None, title='Bare') frame.Show() return True app = App() a ...

  8. [Python] wxPython 基本控件 (转)

    转自:http://www.cnblogs.com/wangjian8888/p/6028777.html 一.静态文本控件 wx.StaticText(parent, id, label, pos= ...

  9. 嵌入式web服务器BOA的移植及应用

    嵌入式web服务器子系统 一.嵌入式web服务器的控制流程 如下图所示,嵌入式web服务器可实现通过网络远程控制嵌入式开发板,便捷实用. 控制流程:浏览器 --->>>嵌入式开发板 ...

随机推荐

  1. 【Shell脚本学习13】Shell数组:shell数组的定义、数组长度

    Shell在编程方面比Windows批处理强大很多,无论是在循环.运算. bash支持一维数组(不支持多维数组),并且没有限定数组的大小.类似与C语言,数组元素的下标由0开始编号.获取数组中的元素要利 ...

  2. oracle数据操纵语言(DML)data manipulation language

    数据库操纵语言(DML)用于查询和操纵模式对象中的数据,它不隐式地提交当前事务. SELECTINSERTUPDATEDELETECALLEXPLAIN PLANLOCK TABLEMERGE使用算术 ...

  3. [转]在WPF中使用WinForm控件方法

    本文转自:http://blog.csdn.net/lianchangshuai/article/details/6415241 下面以在Wpf中添加ZedGraph(用于创建任意数据的二维线型.条型 ...

  4. Android 软键盘操作

    <activity android:windowSoftInputMode=["stateUnspecified", "stateUnchanged", ...

  5. Jfinal----Handler之责任链设计模式

    Jfinal handler的处理采用了责任链设计模式 有关责任链模式,推荐看: <JAVA与模式>之责任链模式 1.实现Handler只需要继承Handler public class ...

  6. Part 5 Select statement in sql server

    Select specific or all columns select * from 表名 select * from Student select 列名,列名... from 表名 select ...

  7. 别人网站生成的json

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sb.ToString()); WebResponse rep = req.GetResp ...

  8. HTML+CSS学习总结:

    1. 注释:<div> 是一个块级元素,也就是说,浏览器通常会在 div 元素前后放置一个换行符. 提示:请使用 <div> 元素来组合块级元素,这样就可以使用样式对它们进行格 ...

  9. lua定时器与定时任务的接口设计

    在所有的服务器编程当中,定时任务永远是一个不可或缺的需求.最直接的需求就是,每天凌晨0点0分的时候总是有一大堆的各种精力重置.怎么来设计这个接口呢,想了几个方案: 每秒触发 每分钟触发 每整点触发 每 ...

  10. NAT

      WRITE BY YANGWJ 一.            配置静态Nat 实验图如下: 1.         将网络基本条件配置好,包括路由要可达,即pc1可以ping到server1 2.   ...