简体   繁体   English

wxpython:创建笔记本时,treectrl中的EVT_TREE_SEL_CHANGED事件

[英]wxpython: EVT_TREE_SEL_CHANGED event in treectrl in notebook when created

I am learning wxpython and have a question. 我正在学习wxpython并有一个问题。

When I create a treectrl within framework and call framework.show() , the first item in the treectrl is automatically selected (ie, EVT_TREE_SEL_CHANGED event is fired). 当我在framework中创建treectrl并调用framework.show()treectrl的第一项会自动被选择(即, EVT_TREE_SEL_CHANGED事件)。 However, when I create a treectrl in a panel, add the panel to a notebook and add the notebook to framework, the EVT_TREE_SEL_CHANGED event is not fired when the framework.show() is called. 但是,当我在面板中创建treectrl ,将面板添加到笔记本中并将笔记本添加到框架中,调用framework.show()时不会触发EVT_TREE_SEL_CHANGED事件。 Instead, when I select an item in the treecontrol later after the initial rendering, two EVT_TREE_SEL_CHANGED are fired (one for the first item which is supposed to be fired during the initial rendering and the other one for the selected item). 相反,当我在初始渲染之后稍后在treecontrol选择一个项目时,将treecontrol两个EVT_TREE_SEL_CHANGED (一个用于在初始渲染期间应被触发的第一个项目,另一个用于所选项目的对象)。

panel.SetFocus() in the bottom of framework.__init__() fix this problem -- ie, fires EVT_TREE_SEL_CHANGED to select the first item during the initial rendering. framework.__init__()底部的panel.SetFocus() framework.__init__()解决了此问题-即,在初始渲染期间触发EVT_TREE_SEL_CHANGED以选择第一个项目。 But, I wonder why this is happening. 但是,我不知道为什么会这样。 Does anybody know why EVT_TREE_SEL_CHANGED is blocked in the initial rendering when the tree control is contained in the panel of notebook? 当树形控件包含在笔记本面板中时,有人知道为什么EVT_TREE_SEL_CHANGED在初始渲染中被阻止吗?

I don't know why exactly does this happen but this looks like a bug in wxWidgets. 我不知道为什么会这样,但这看起来像是wxWidgets中的错误。 In practice, this means that it you shouldn't rely on this behaviour because it might (and in fact I'm pretty sure it does) behave differently under other platforms and also could change in future wxWidgets versions. 在实践中,这意味着您不应该依赖此行为,因为它在其他平台上的行为可能会有所不同(实际上我很确定确实如此),并且在将来的wxWidgets版本中也可能会发生变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM