在 WxPython 中将位图放在 StaticBitmap 之上

Put a bitmap on top of StaticBitmap in WxPython

我有一个带有面板的应用程序 放置静态位图(wx.StaticBitmap)的位置 在 GridBagSizer 中。 我想将位图放在某些 静态位图,将部分覆盖它和它的邻居。

我一直在这样尝试:

self.panel = wx.Panel(self, -1, style=wx.TRANSPARENT_WINDOW)
self.panel.Bind(wx.EVT_PAINT, self.place_bitmap)

.
.
.

def place_bitmap(self, *args):
    dc = wx.ClientDC(self.panel)  # or wx.PaintDC(self.panel)

    for xy in self.coordinates:
        dc.DrawBitmap(self.top_bitmap, xy[0], xy[1], 0)

    self.panel.Layout()

如果我更改 dc.DrawBitmap() 中的坐标 它显示到 self.panel 中没有静态位图的地方。 但我无法让它显示在静态位图之上。 所以它似乎在它们下面呈现?

如何让 top_bitmap 置顶?

您无法在 child windows 之上进行移植。一般的解决方案是创建一个 child window child window 并在其上绘制,但在你的情况下,使用自定义 [=18 可能会更简单=] 而不是 wxStaticBitmap 无论如何,这是一个非常简单的 class -- 然后你就可以在里面画任何你想画的东西了。