我正在创建具有数百万个节点的树,但是当我切换到在树控件(wx.TR_MULTIPLE)上使用多选时,对树的操作变慢,我只单击选择一个节点,这花了我几秒钟的时间。当我使用单选样式(wx.TR_SINGLE)时,不会发生这种情况。
我试图不为任何节点设置数据,也没有使用任何事件,但是它仍然很慢。有什么方法可以在树控件上使用多选,而树仍然像单选一样快速?
我在下面粘贴了修改后的演示代码:
import wx
class MyTree(wx.TreeCtrl):
def __init__(self, parent, id, pos, size, style):
wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.item_changed)
def item_changed(self, evt):
print(self.GetItemData(evt.GetItem()))
class TreePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.tree = MyTree(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_HAS_BUTTONS | wx.TR_MULTIPLE)
self.root = self.tree.AddRoot('ROOT')
node1 = self.tree.InsertItem(self.root, 0, 'Node 1', data='node 1')
for i in range(1000000):
self.tree.PrependItem(node1, 'Sub node 1: ' + str(i), data='Sub node 1: ' + str(i))
self.tree.Expand(self.root)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.tree, 1, wx.EXPAND)
self.SetSizer(sizer)
class MainFrame(wx.Frame): …Run Code Online (Sandbox Code Playgroud) 我正在使用Debian Stable Linux和python 3.5,我正在尝试使用以下命令安装新的wxpython(phoenix):
pip3 install --upgrade wxpython
Run Code Online (Sandbox Code Playgroud)
但是,它会因以下错误而停止:
checking for CAIRO... yes
checking for cairo_push_group... yes
checking for GST... configure: WARNING: GStreamer 1.0 not available, falling back to 0.10
checking for GST... configure: WARNING: GStreamer 0.10 not available, falling back to 0.8
configure: error: GStreamer not available
Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build.py", line 1269, in cmd_build_wx
wxbuild.main(wxDir(), build_options)
File "/tmp/pip-build-pdn9eo0c/wxpython/buildtools/build_wxwidgets.py", line 376, in main
"Error running configure")
File "/tmp/pip-build-pdn9eo0c/wxpython/buildtools/build_wxwidgets.py", line …Run Code Online (Sandbox Code Playgroud)