Here's a look at the ways to create toolbars, status bars, and menus, as shown in the following example:
Import WX
Class Toolbarframe (wx. Frame):
def __init__ (self,parent,id):
Wx. frame.__init__ (self,parent,id, ' ToolBar ', size= (300,200))
Panel=wx. Panel (self)
Panel. Setbackgroundcolour (' White ')
Statusbar=self. Createstatusbar ()
Toolbar=self. Createtoolbar ()
Toolbar.addsimpletool (wx. NewId (), Wx. Bitmap (' toolbar.bmp '), "new", "long Help for ' new '")
Toolbar.realize ()
Menubar=wx. MenuBar ()
Menu1=wx. Menu ()
Menubar.append (menu1, "&file")
Menu2=wx. Menu ()
menu2. Append (wx. NewId (), "©", "Copy in status Bar")
menu2. Append (wx. NewId (), "&cut", "")
menu2. Append (wx. NewId (), "Paste", "")
menu2. Appendseparator ()
menu2. Append (wx. NewId (), "&options ...", "Display Option")
Menubar.append (menu2, "&edit")
Self. Setmenubar (menuBar)
If __name__== ' __main__ ':
App=wx. Pysimpleapp ()
Frame=toolbarframe (parent=none,id=-1)
Frame. Show ()
App. Mainloop ()
The results of the operation are as Follows:
The first is the creation of StatusBar: Statusbar=self. Createstatusbar () Here's A way to use a frame, createstatusbar (), which defaults to creating a default and frame-aligned status bar under the current frame, which is very simple, one sentence to Fix. of course, WX provides us with a special toolbar class, and its corresponding many methods, such as create (), this is not introduced here First. StatusBar is the display of some other application-provided text, where the size of the text and other properties by the system Default.
The following is the creation of toolbar.
Toolbar=self. Createtoolbar ()
Toolbar.addsimpletool (wx. NewId (), Wx. Bitmap (' toolbar.bmp '), "new", "long Help for ' new '")
Toolbar.realize ()
The first sentence or call a method in the frame createtoolbar, return a toolbar object, is also a very simple method, the following is the load on this toolbar we want to the icon, The usage of Addsimpletool can be helped by Help: Addsimpletool (self, id, bitmap, shorthelpstring= ", longhelpstring=", istoggle=0) Unbound Wx._controls. ToolBar method
Old Style method to add a tool to the toolbar.
One of the parameter longhelpstring is the Help information to display to the status bar. The last realize () is to make the toolbar appear on the WINDOW.
The last thing left is to create the MENU.
MenuBar () is the creation of a menu bar, where the menu is to be Placed. Menu () is the creation of menus, Append () is the way to add a menu to the menu bar, or the handle menu is added to the MENU. Self. Setmenubar (menuBar) is a method that calls the frame to place the menu bar, which is automatically placed in the appropriate Position.
Wxpython creating toolbars and menu bars