wxPython GUI基本框架

先写一个基本的框架,还需要持续更新. 同时,作为新建GUI程序的模板使用.

 1 #/usr/bin/python

 2 #-*-<coding=UTF-8>-*-

 3 

 4 """

 5 本例为一个基本的wxPython GUI程序,包括菜单栏,工具栏,面板容器,状态栏

 6 """

 7 

 8 import wx

 9 

10 class GuiMainFrame(wx.Frame):

11     

12     def __init__(self):

13     wx.Frame.__init__(self,parent=None,id=-1,title="",pos=wx.DefaultPosition,size=wx.DefaultSize)

14     panel = wx.Panel(self)

15     panel.SetBackgroundColour("White")

16 

17     #menu bar

18     menubar = wx.MenuBar()

19     

20     #File menu

21     fileMenu = wx.Menu()

22     fileMenu.Append(-1,"&Open","")

23     menubar.Append(fileMenu,"&File")

24 

25     #Edit menu

26     editMenu = wx.Menu()

27     editMenu.Append(-1,"&Copy","")

28     menubar.Append(editMenu,"&Edit")

29 

30     #Help/About menu

31     helpMenu = wx.Menu()

32     helpMenu.Append(-1,"About","")

33     menubar.Append(helpMenu,"&Help")

34     

35     #调用SetMenuBar,使其在框架中显示出来

36     self.SetMenuBar(menubar)

37     

38     #添加工具栏,注意:用toolbar = wx.ToolBar()创建不行,会被其它的控件盖掉,这是为什么?

39     #toolbar = wx.ToolBar(self)

40     toolbar = self.CreateToolBar()

41     tsize = (24,24)

42     new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW,wx.ART_TOOLBAR,tsize)

43     toolbar.AddSimpleTool(-1,new_bmp,"Long Help for 'New'")

44     toolbar.Realize()

45     

46     #添加状态栏

47     statusbar = self.CreateStatusBar()

48 

49 

50 if __name__ == "__main__":

51     app = wx.PySimpleApp()

52     frame = GuiMainFrame()

53     frame.Show()

54     app.MainLoop()

 

你可能感兴趣的:(wxPython)