<p>我假设linux/mac上的工具栏大小是(0,0)的原因是b/c,没有附加工具。若要解决此问题,可以设置工具栏的最小大小,然后通过向工具栏大小添加框架标题和边框来计算框架大小。你知道吗</p>
<pre><code>import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
vbox = wx.BoxSizer(wx.VERTICAL)
toolbar1 = wx.ToolBar(self)
toolbar1.SetBackgroundColour(wx.RED)
toolbar1.SetToolBitmapSize(wx.Size(64, 64))
# prevent the sizer from setting the size to (0, 0) when there are no tools attached
toolbar1.SetMinSize((64, 64))
toolbar1.Realize()
vbox.Add(toolbar1, 0, wx.EXPAND)
self.SetSizer(vbox)
self.SetTitle('Toolbars')
self.Centre()
vbox.Fit(self)
self.Layout()
# calculate the frame caption height
caption_height = wx.SystemSettings.GetMetric(wx.SYS_CAPTION_Y, self)
# *2 for the left and right border
border_width = wx.SystemSettings.GetMetric(wx.SYS_BORDER_X, self) * 2
# get the size of the toolbar
sx, sy = toolbar1.GetSize()
# set the frame size by adding the toolbar size to the border/caption size
self.SetSize((sx + border_width, sy + caption_height))
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
</code></pre>