简体   繁体   English

避免单击以摆脱笔记本中的wxPython TreeCtrl

[英]Avoid click to get out of wxPython TreeCtrl in a Notebook

Below is a very simple wxPython code creating a Notebook inside which are several panels containing TreeCtrl objects. 下面是一个非常简单的wxPython代码,用于创建一个Notebook,其中包含几个包含TreeCtrl对象的面板。

Using it, I get a behavior I would like to avoid: 使用它,我会避免以下行为:

When I click in a tree, then I cannot switch directly to another page of the notebook without clicking first outside the tree. 当我单击树时,如果不先在树外单击,便无法直接切换到笔记本的另一页。 This means that it needs two clicks to change the notebook page: One to get outside the tree, another to switch the page. 这意味着需要两次单击来更改笔记本页面:一次进入树外,另一次切换页面。

I would like to be able to do this in one single click. 我希望能够一键执行此操作。

The code: 编码:

import wx

class TestFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY)

        # Create the notebook
        notebook = wx.Notebook(self)

        # Put panels in the notebook
        notebook.AddPage(TestPanel(notebook), "Page 1")
        notebook.AddPage(TestPanel(notebook), "Page 2")

        # Display the window
        self.Show(True)


class TestPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        # Create the sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # Create the tree
        tree = wx.TreeCtrl(self)
        sizer.Add(tree, 1, wx.EXPAND)

        # Create nodes in the tree
        root = tree.AddRoot("root")

        tree.AppendItem(root, "item 1")
        tree.AppendItem(root, "item 2")
        tree.AppendItem(root, "item 3")

        # Expand the root node
        tree.Expand(root)


if __name__ == "__main__":

    # Create an application without redirection of stdout/stderr to a window
    application = wx.App(False)

    # Open a main window
    frame = TestFrame()

    # Launch the application
    application.MainLoop()

This looks like this bug which should be fixed in 3.0.2. 这看起来像应该在3.0.2中修复的错误 If you're using an earlier version, please upgrade. 如果您使用的是早期版本,请升级。

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

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