Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python wx.GenericDirCtrl事件';s处理_Python_Wxpython - Fatal编程技术网

Python wx.GenericDirCtrl事件';s处理

Python wx.GenericDirCtrl事件';s处理,python,wxpython,Python,Wxpython,我正在使用此控件,但无法处理控件单击(和其他事件)。 这是我的代码: class BoExplorerPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, wx.ID_ANY) self.initComponents() # initialize Window components def initComponents(self): print "Iniz

我正在使用此控件,但无法处理控件单击(和其他事件)。 这是我的代码:

class BoExplorerPanel(wx.Panel):
  def __init__(self, parent):
     wx.Panel.__init__(self, parent, wx.ID_ANY)

     self.initComponents() # initialize Window components

  def initComponents(self):
     print "Inizializzo i controlli"
     # controls
     resizeBox = wx.BoxSizer(wx.VERTICAL)

     self.dirBrowser = wx.GenericDirCtrl(self, wx.ID_ANY, style = wx.DIRCTRL_DIR_ONLY)

     resizeBox.Add(self.dirBrowser, 1, wx.EXPAND | wx.ALL)

     self.SetSizerAndFit(resizeBox)

     # events
     self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.dirBrowser_OnItemSelected,   self.dirBrowser)
     self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.dirBrowser_OnRightClick, self.dirBrowser)
     self.Bind(wx.EVT_TREE_SEL_CHANGED, self.dirBrowser_OnSelectionChanged, self.dirBrowser)

     # panel's properties

  def dirBrowser_OnItemSelected(self, event):
     print "CLicked"

  def dirBrowser_OnRightClick(self, event):
     print "Right Click"

  def dirBrowser_OnSelectionChanged(self, event):
     print "Selection Changed"

您需要绑定到目录类的TreeCtrl,而不是该类本身

修正了下面的代码。注意事件处理程序中对event.Skip()的调用(注释它以查看其效果)

#!/usr/bin/python
import wx

class BoExplorerPanel(wx.Frame):
  def __init__(self):
     wx.Frame.__init__(self, None)

     self.initComponents() # initialize Window components

  def initComponents(self):
     print "Inizializzo i controlli"
     # controls
     resizeBox = wx.BoxSizer(wx.VERTICAL)

     self.dirBrowser = wx.GenericDirCtrl(self, wx.ID_ANY, style = wx.DIRCTRL_DIR_ONLY)

     resizeBox.Add(self.dirBrowser, 1, wx.EXPAND | wx.ALL)

     self.SetSizerAndFit(resizeBox)

     # events
     tree = self.dirBrowser.GetTreeCtrl()
     self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.dirBrowser_OnItemSelected, tree)
     self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.dirBrowser_OnRightClick, tree)
     self.Bind(wx.EVT_TREE_SEL_CHANGED, self.dirBrowser_OnSelectionChanged, tree)

     # panel's properties

  def dirBrowser_OnItemSelected(self, event):
     print "CLicked"
     event.Skip()

  def dirBrowser_OnRightClick(self, event):
     print "Right Click"
     event.Skip()

  def dirBrowser_OnSelectionChanged(self, event):
     print "Selection Changed"
     event.Skip()


app = wx.App(False)
f = BoExplorerPanel()
f.Show()
app.MainLoop