简体   繁体   中英

wxpython toolbar not shown in os x

I have a python script for GUI using wxpython. It works perfectly fine in Windows, however, when I run the script in OS X, the toolbar is now shown (I installed wxpython from its official website and used the cocoa version, and I am using OS X 10.10 and python 2.7). Following is the part of the code regarding the toolbar:

self.toolBar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL|wx.TB_FLAT|wx.TB_DOCKABLE)
self.myChoice = ComboBoxWithHelp(self.toolBar, wx.NewId(), size=(200, -1), value=..., choices=..., style=wx.CB_DROPDOWN,)
self.toolBar.AddControl(self.myChoice)

iconname = 'icons/new.png'
self.toolBar.AddSimpleTool(1, wx.Image(iconname, wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'New', 'New')

...
self.toolBar.Realize()
self.SetToolBar(self.toolBar)

Nothing is shown below the menu bar, however the space is left there. Did I installed the wxpython wrongly or use the function wrongly?

By the way, the above code also works for Ubuntu.

What is self in this code? Toolbars are a little different on OSX, and and can be a bit tricky, so there may be some issues if self is not a wx.Frame or a class derived from wx.Frame . This is because the native toolbars are actually part of the frame rather than an independent widget. It should be switching to a non-native toolbar if the parent is not the frame, but then you'll need to manage its size and layout yourself.

If self is already the frame then you may want to try not specifying the style flags and let it just use the default style, or you can try creating the toolbar like this instead and let the frame create it:

self.toolBar = self.CreateToolBar()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM