1 # /Usr/bin/Python 2 # -*-<Coding = UTF-8> -*- 3 4 """ 5 This example is a basic wxpython GUI.ProgramIncluding menu bar, toolbar, panel container, and status bar 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 # Why use frame binding? Why not use menu binding: 30 # Self. color. BIND (wx. evt_menu, self. oncolorchoice)
# If the compilation fails, attributeerror: 'menuitem' object has no attribute 'bind' is displayed' 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 # Call setmenubar to display it in the Framework. 40 Self. setmenubar (menubar) 41 42 # Add a toolbar. Note: if you cannot create a toolbar with toolbar = wx. toolbar (), it will be replaced by other controls. Why? 43 # Toolbar = wx. toolbar (Self) 44 Toolbar = Self. createmedilbar () 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 # Add Status Bar 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 ()