【问题标题】:Enter key behavior in wx.grid在 wx.grid 中输入关键行为
【发布时间】:2011-12-20 01:47:45
【问题描述】:

谷歌搜索很多,但没有任何结果...按回车键时网格的默认行为是向下移动光标。但我必须让单元格编辑器在当前单元格中打开。可以很方便的hook按键事件,但是怎么打开编辑器呢?

【问题讨论】:

    标签: grid wxpython enter


    【解决方案1】:
    import wx
    import wx.grid
    
    class MyGrid(wx.grid.Grid):
        def __init__(self, *args, **kwargs):
            wx.grid.Grid.__init__(self, *args, **kwargs)
            self.CreateGrid(8, 3)
    
            self.editor = wx.grid.GridCellChoiceEditor(["One", "Two", "Three"])
            self.SetCellEditor(1, 1, self.editor)
            self.SetCellValue(1, 0, "And here.")
            self.SetCellValue(1, 1, "Try here.")
    
            self.Bind(wx.EVT_KEY_DOWN, self.OnEnter)
    
    
        def OnEnter(self, e):
            if e.GetKeyCode() == wx.WXK_RETURN or e.GetKeyCode() == wx.WXK_NUMPAD_ENTER:
                self.EnableCellEditControl()
            else:
                e.Skip()
    
    
    class MainWindow(wx.Frame):
        def __init__(self, *args, **kwargs):
            wx.Frame.__init__(self, *args, **kwargs)
            self.grid = MyGrid(self)
            self.Show()
    
    
    
    app = wx.App(False)
    win = MainWindow(None)
    app.MainLoop()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 2017-01-05
      相关资源
      最近更新 更多