Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wx.gizmos.TreeListCtrl, The keyboard cannot trigger events: wx.EVT_TREE_ITEM_ACTIVATED . Can only be triggered by double-clicking the mouse #2551

Open
tuoniaoren opened this issue May 15, 2024 · 1 comment

Comments

@tuoniaoren
Copy link

import wx.gizmos as gizmos
import wx
ID_PARAM_ARRAY = wx.NewIdRef(count=1)

class MyFrame(wx.Frame):
def init(self,parent=None):
super(MyFrame, self).init(parent, -1, "数表控件", size=(450, 250))

    #创建树表控件
    self.tree = gizmos.TreeListCtrl(self, ID_PARAM_ARRAY, style=wx.TR_DEFAULT_STYLE|wx.TR_FULL_ROW_HIGHLIGHT)

    self.il = wx.ImageList(16,16,True)
    #给树表控件添加图标
    # def GetBitmap(self, id, client=None, size=None)   ArtProvider系统自己提供的位图类
    self.il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER,wx.ART_OTHER,(16,16)))
    self.il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,wx.ART_OTHER,(16,16)))
    self.il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_OTHER,(16,16)))
    self.tree.SetImageList(self.il)
    #添加树表的列
    self.tree.AddColumn("第1列")
    self.tree.AddColumn("第2列")
    self.tree.AddColumn("第3列")
    self.tree.SetColumnWidth(0,186)

    self.root = self.tree.AddRoot("root")
    self.tree.SetItemText(self.root,"随便设置",1)   #设置第一行第二列的文本
    self.tree.SetItemText(self.root,"与根同列",2)   #设置第一行第三列的文本

    for x in range(5):
        child = self.tree.AppendItem(self.root,str(x))  #添加一行
        self.tree.SetItemText(child,str(x),0)   #按照索引设置每一列的数据
        self.tree.SetItemText(child,str(x),1)
        self.tree.SetItemText(child,str(x),2)

        #按照索引设置对应的图标
        self.tree.SetItemImage(child,0,which = wx.TreeItemIcon_Normal)  #正常的时候显示的图标的索引值
        self.tree.SetItemImage(child,1,which = wx.TreeItemIcon_Expanded)    #表展开的时候所显示的图标的索引值

        for y in range(5):
            last = self.tree.AppendItem(child,str(y))
            self.tree.SetItemText(last,str(x)+"-"+str(y),0)
            self.tree.SetItemText(last,str(x)+"-"+str(y),1)
            self.tree.SetItemText(last,str(x)+"-"+str(y),2)
            self.tree.SetItemImage(last,0,which = wx.TreeItemIcon_Normal)
            self.tree.SetItemImage(last,1,which = wx.TreeItemIcon_Expanded)

    self.tree.Expand(self.root)
    self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_change_param, id=ID_PARAM_ARRAY)

def on_change_param(self, evt):
    print(1111)

app = wx.App()

frame = MyFrame()
frame.Show()

app.MainLoop()

python==3.10
wxpython==4.2.1

@reticulatus
Copy link
Contributor

Try replacing:

        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_change_param, id=ID_PARAM_ARRAY)

with:

        self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_change_param)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants