wx python 3.0.2经典的“CheckListBox”对象没有属性“GetItemHeight”

2024-10-05 10:09:13 发布

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

研究如何将我的wx2.8python应用程序移植到wx3.0.2classic(是时候了)并遇到了这个障碍。显然GetItemHeight不再是类的一部分:

bash\basher\patcher_dialog.py:519: wxPyDeprecationWarning: Accessing deprecated property. 
  mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
Traceback (most recent call last):
  File "bash\basher\patcher_dialog.py", line 519, in OnMouse
    mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
AttributeError: 'CheckListBox' object has no attribute 'GetItemHeight'

人们使用它们来获取鼠标事件处理程序中悬停的项目(下面的gPatchers是一个wx.CheckListBox):

^{pr2}$

那么如何在wxpython3.0.2中实现这一点呢?在

编辑:在wx用户邮件列表中交叉发布:https://groups.google.com/forum/#!topic/wxpython-users/mMYr-51sE4s


Tags: pyselfbashevent应用程序dialogwx障碍
2条回答

您只需使用底层类ListBox中的^{}来查找哪个项位于给定的x/y坐标。Item是列表元素的int索引。该文档适用于wxPython phoenix,但在wxPython MSW classic 3.0.2下工作原理相同。在

    # lb is a wx.(Check)ListBox instance
    lb.Bind(wx.EVT_MOTION, self.OnMouse)

def OnMouse(self, evt):
    obj = evt.GetEventObject()
    x, y = evt.GetPosition()
    if isinstance(obj, wx.ListBox):
        item = obj.HitTest(wx.Point(x, y))
        # do something with item index information

嗨,你可以试试下面的技巧

I couldn't try this with your code but it is also the way you can find the height of CheckListBox

 self.gPatchers.GetClientRect()[3]

It will return the height in pixel. GetClientRect() method will return tuple of 4 value (x,y,width,height)

相关问题 更多 >

    热门问题