学习wxPython的一个例子

这段代码显示了如何创建一个带有状态栏,菜单栏,工具栏的一般win32窗口,代码来自《wxPython in action》一书。

# -*- coding: gb2312 -*-
'''
Created on 2010-6-2

@author: ywxgod
'''


import wx
import wx.py.images as images

class toolBarFrame(wx.Frame):
    
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,"toolBarFrame",(0,0),(300,300))
        panel = wx.Panel(self)
        panel.SetBackgroundColour("white")
        statusBar = self.CreateStatusBar()
        toolBar = self.CreateToolBar()
        toolBar.AddSimpleTool(wx.NewId(),images.getPyBitmap(),"New","Long help for 'New'")
        toolBar.AddSimpleTool(wx.NewId(),images.getPyBitmap(),"hooh","another help fo new")
        toolBar.Realize()
        menuBar = wx.MenuBar()
        
        menu1 = wx.Menu()
        menuBar.Append(menu1,'hello')
        menu2 = wx.Menu()
        menu2.Append(wx.NewId(),"As3","I like it")
        menu2.Append(wx.NewId(),"Copy","速度快")
        menu2.Append(wx.NewId(),"Paste","发生的")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(),"more","Display options")
        menuBar.Append(menu2,"Python")
        self.SetMenuBar(menuBar)
        


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = toolBarFrame(None,-1)
    frame.Show()
    app.MainLoop()

相对于原来书中的代码,我做了如下修改:

1。加入了中文的字符,如鼠标滑过菜单时状态栏的文字说明

2。修改了原来import images为import wx.py.images as images,因为原来的有错!

3。加入中文的字符后,会出现乱码,所以在第一行加入了编码的语句,此句只能放在第一行!

程序运行截图:

程序截图

posted @ 2010-06-03 21:18  ywxgod  阅读(710)  评论(0编辑  收藏  举报