这会将鼠标和项目选择事件分配给同一事物,然后使用event.Skip() 确保我们都能看到两者。
也许这可能会让您对如何进步有所了解。
与 Shift、Ctrl 等组合使用,mods 会根据按下的内容为您提供不同的数字。
import wx
class Myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
pan = wx.Panel(self)
self.listC = wx.ListCtrl(pan, style=wx.LC_REPORT)
self.listC.InsertColumn(0, 'Column1', width=50)
self.listC.InsertColumn(1, 'Column2', width=50)
self.listC.InsertColumn(2, 'Column3', width=50)
self.listC.Bind(wx.EVT_LEFT_DOWN, self.ListClick)
self.listC.Bind(wx.EVT_LIST_ITEM_SELECTED, self.ListSelected)
self.listC.InsertStringItem(0,"Item1")
self.listC.SetStringItem(0, 1,"Col 1 Item")
self.listC.SetStringItem(0, 2,"Col 2 Item")
self.listC.InsertStringItem(1,"Item2")
self.listC.SetStringItem(1, 1,"Col 1 Item")
self.listC.SetStringItem(1, 2,"Col 2 Item")
def ListClick(self, event):
mods = event.GetModifiers()
print mods
event.Skip()
def ListSelected(self, event):
print "selected"
if __name__ == "__main__":
App = wx.App()
Myframe().Show()
App.MainLoop()