【问题标题】:wxpython simulating bitmap button clickwxpython模拟位图按钮点击
【发布时间】:2014-05-23 19:15:18
【问题描述】:

我正在尝试模拟位图按钮的按钮单击。代码不会抛出任何错误,也不会执行任何操作...

self.buttonImage = wx.Bitmap(button_image, wx.BITMAP_TYPE_PNG)
self.button = wx.BitmapButton(self, -1, self.buttonImage, pos=(100, 300), style = wx.NO_BORDER)

evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self.button.GetId())
wx.PostEvent(self, evt)

【问题讨论】:

    标签: python wxwidgets


    【解决方案1】:

    A matching answer has been given already in another post. 假设您在同一个线程中(这应该是 wxPython 中最常见的情况),您必须将 PostEvent 中的 self 替换为与按钮相关的内容。当然,您发布的事件不会产生任何结果,因为您没有将事件绑定到位图按钮。

    # button creation
    self.button = wx.BitmapButton(pnl, -1, self.buttonImage, pos=(100, 300), style=wx.NO_BORDER)
    # Bind an event
    self.button.Bind(wx.EVT_BUTTON, self.on_btn)
    
    # GUI test code
    testbtn = frm.button # the button to be tested
    evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, testbtn.GetId())
    wx.PostEvent(testbtn, evt) # try frm instead of testbtn and it will not work
    

    【讨论】:

      猜你喜欢
      • 2011-07-18
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 2015-06-28
      相关资源
      最近更新 更多