带有禁用工具的wxPython工具栏未按预期呈现

2024-10-03 09:15:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个基于wxPython的应用程序,其中一个工具栏有问题。它最初是针对wxpython2.8.10/python2.6编写的,但目前运行的是wxpython4.0.4/python2.7.15。你知道吗

工具栏同时包含(16,16)和(32,32)位图。当一切都启用时,所有位图都会呈现良好效果。但是,任何被禁用的位图看起来都像是试图在其空间的左上角(16,15)进行渲染。我尝试过切换到调用(16,16)位图,尝试过将bmpDisabled设置为各种值,并更改工具栏上的SetToolBitmapSize,但似乎没有任何方法可以修复该行为。你知道吗

启用时工具栏呈现的示例

Example of the toolbar rendering when enabled

禁用第1个(16,16)和第3个(32,32)工具栏的示例。第二个(16,16)仍然启用。你知道吗

Example of the toolbar with the 1st (16,16) and 3rd (32,32) disabled

代码非常简单:

   self._tb = self.CreateToolBar()
   self._tb.SetToolBitmapSize((32,32))

   image =   getTransparentwxBitmap("icons/foo.bmp")
   item =   self._tb.AddCheckTool(self.TB_FOO_ID, "", image, wx.NullBitmap, "Foo Panel", "Show/Hide the foo panel")
    self._tb.Bind(wx.EVT_TOOL,self.onToolClick,item)
    self._tb.EnableTool(self.TB_FOO_ID,False)

   image =   getTransparentwxBitmap("icons/bar.bmp")
   item =   self._tb.AddCheckTool(self.TB_BAR_ID, "", image, wx.NullBitmap, "Bar Panel", "Show/Hide the bar panel")
   self._tb.Bind(wx.EVT_TOOL,self.onToolClick,item)
   self._tb.EnableTool(self.TB_BAR_ID,False)

   imgPath = "images/baz.png"
   image = wx.Bitmap(imgPath)
   item = self._tb.AddTool(self.TB_BAZ_ID, "", image, shortHelp="BAZ Tool")
   self._tb.EnableTool(self.TB_BAZ_ID, False)
   .
   .
   .
   other tools
   .
   .
   .

   self._tb.Realize()

有什么想法吗?你知道吗


Tags: imageselfidfalse示例bazitemtb