#!/usr/bin/python
#-*- coding:utf8 -*-
import wx
import wx.html as html
class IconFrame(wx.Frame):
def __init__(self, root):
wx.Frame.__init__(self, root, -1, u"Icon示例", size=(300,300), style=wx.DEFAULT_FRAME_STYLE ^ (wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX))
#保证窗口不能最小化 或者 最大化
saveImg = wx.Image('save_page.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
homeImg = wx.Image('go_home.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
setImg = wx.Image('settings.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
forwardImg = wx.Image('go_forward.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
backImg = wx.Image('go_back.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
toolBar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.TB_TEXT)
toolBar.AddSimpleTool(100, saveImg, 'Save Page')
toolBar.AddSimpleTool(200, homeImg, 'Go Home')
toolBar.AddSimpleTool(220, backImg, 'Go Back')
toolBar.AddSimpleTool(230, forwardImg, 'Go Forward')
toolBar.AddSimpleTool(400, setImg, 'Settings')
toolBar.Realize()
self.CreateStatusBar()
#MDI窗口的示例 多文档
class MDIFrame(wx.MDIParentFrame):
def __init__(self, root):
wx.MDIParentFrame.__init__(self, root, -1, u'MDI示例', size=(300, 300))
menuBar = wx.MenuBar()
menu = wx.Menu()
menu.Append(100, u"新建(&N)")
menu.Append(101, u"退出(&E)")
menuBar.Append(menu, u"文件(&F)")
self.Bind(wx.EVT_MENU, self.OnNewMDI, id=100)
self.Bind(wx.EVT_MENU, self.OnExit, id=101)
self.SetMenuBar(menuBar)
def OnExit(self, event):
self.Close(True)
def OnNewMDI(self, event):
win = wx.MDIChildFrame(self, -1, u'子窗口')
win.Show()
#将一个浏览器窗口的示例
class HtmlFrame(wx.Frame):
def __init__(self, root):
wx.Frame.__init__(self, root, -1, u"HTML窗口", size=(300,300))
self.html = HtmlPanel(self, -1)
self.html.LoadUrl('test.html')
def OnCloseWindow(self, event):
self.Destroy()
class HtmlPanel(html.HtmlWindow):
def __init__(self, parent, id):
html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE)
def LoadUrl(self, url):
self.LoadPage(url)
class MyApp(wx.App):
def OnInit(self):
#self.frame = IconFrame(None)
#self.frame = MDIFrame(None)
self.frame = HtmlFrame(None)
self.frame.Show()
return True
app = MyApp()
app.MainLoop()
QQ交流群: 204944806