wxPython中colour choice对话框实例

 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         self.panel = wx.Panel(self)

15         self.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         self.copy = editMenu.Append(-1,"&Copy","")

28         self.color = editMenu.Append(-1,"Colo&r")

29         #为什么要用frame绑定,为什么不用menu来绑定:

30         #self.color.Bind(wx.EVT_MENU,self.OnColorChoice)
       #编译不过,提示AttributeError: 'MenuItem' object has no attribute 'Bind'
31 self.Bind(wx.EVT_MENU,self.OnColorChoice,self.color) 32 menubar.Append(editMenu,"&Edit") 33 34 #Help/About menu 35 helpMenu = wx.Menu() 36 helpMenu.Append(-1,"About","") 37 menubar.Append(helpMenu,"&Help") 38 39 #调用SetMenuBar,使其在框架中显示出来 40 self.SetMenuBar(menubar) 41 42 #添加工具栏,注意:用toolbar = wx.ToolBar()创建不行,会被其它的控件盖掉,这是为什么? 43 #toolbar = wx.ToolBar(self) 44 toolbar = self.CreateToolBar() 45 tsize = (24,24) 46 new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW,wx.ART_TOOLBAR,tsize) 47 toolbar.AddSimpleTool(-1,new_bmp,"Long Help for 'New'") 48 toolbar.Realize() 49 50 #添加状态栏 51 statusbar = self.CreateStatusBar() 52 53 def OnColorChoice(self,event): 54 colorDialog = wx.ColourDialog(self) 55 colorDialog.GetColourData().SetChooseFull(True) 56 if colorDialog.ShowModal() == wx.ID_OK: 57 self.panel.SetBackgroundColour(colorDialog.GetColourData().GetColour()) 58 colorDialog.Destroy() 59 60 if __name__ == "__main__": 61 app = wx.PySimpleApp() 62 frame = GuiMainFrame() 63 frame.Show() 64 app.MainLoop()

你可能感兴趣的:(wxPython)