【发布时间】:2019-10-09 21:07:39
【问题描述】:
当鼠标悬停在小部件上时,我想更新我的wx.StaticBitmap 的图像。 Baiscally,切换到黑白进行测试。
我的问题是,当调用self.image.SetBitmap(...) 时,图像会在我的窗口中重新定位,并且旧的图像也会停留在旧位置。
附加问题:是否可以在不加载新的 BW 图像的情况下使我的图像变为黑白?
这是我的代码:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kw):
super(Example, self).__init__(*args, **kw)
self.InitUI()
def InitUI(self):
self.panel = wx.Panel(self)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.png = wx.Bitmap("TestButton.png")
self.png_bw = wx.Bitmap("TestButton_bw.png")
self.image = wx.StaticBitmap(self.panel, 1, self.png)
self.image.Bind(wx.EVT_ENTER_WINDOW, self.OnOver)
self.image.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
hbox.Add(self.image,1)
self.panel.SetSizer(hbox)
self.SetTitle('Button Test')
self.Centre()
def OnOver(self, event):
self.image.SetBitmap(self.png_bw)
def OnLeave(self, event):
self.image.SetBitmap(self.png)
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
【问题讨论】:
标签: python python-3.x image wxpython