[英]Avoid click to get out of wxPython TreeCtrl in a Notebook
下面是一个非常简单的wxPython代码,用于创建一个Notebook,其中包含几个包含TreeCtrl对象的面板。
使用它,我会避免以下行为:
当我单击树时,如果不先在树外单击,便无法直接切换到笔记本的另一页。 这意味着需要两次单击来更改笔记本页面:一次进入树外,另一次切换页面。
我希望能够一键执行此操作。
编码:
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()
这看起来像应该在3.0.2中修复的错误 。 如果您使用的是早期版本,请升级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.