小编ROB*_*ROB的帖子

使用ctrl-c和ctrl-v复制并粘贴到wxPython中的wx.Grid中

我正在开发一个带有许多输入表的程序,我正在使用wxPython wx.Grid(主要用于Windows).我注意到ctrl-c和ctrl-v复制和粘贴doe snot只是工作,我搜索解决方案,以防止必须手动输入表中的所有数字.我在这里找到了Ruben Charles的一篇旧帖子:http: //comments.gmane.org/gmane.comp.python.wxpython/26387

这似乎或多或少地做了我想要的,所以我开始使用它并做了一些,我希望是改进.(我使用ctrl-Z为'undo'添加了功能,用于处理单个单元格,如果最后一行或列落在网格表之外,则添加功能.)

有没有更好的方法来做到这一点,或者你可能有改进的建议?特别是:如何使用Python 3.5实现这一功能?

import wx
import wx.grid

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title, pos=wx.DefaultPosition, size=wx.Size(800, 400), style=wx.DEFAULT_FRAME_STYLE):
        wx.Frame.__init__(self, parent, ID, title, pos, size, style)
        agrid = MyGrid(self, -1, wx.WANTS_CHARS)
        agrid.CreateGrid(7, 7)
        for count in range(3):
            for count2 in range(3):
                agrid.SetCellValue(count, count2, str(count + count2))

class MyGrid(wx.grid.Grid):
    """ A Copy&Paste enabled grid class"""
    def __init__(self, parent, id, style):
        wx.grid.Grid.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style)
        wx.EVT_KEY_DOWN(self, self.OnKey)
        self.data4undo = [0, 0, '']

    def OnKey(self, …
Run Code Online (Sandbox Code Playgroud)

python wxpython copy-paste

6
推荐指数
2
解决办法
3752
查看次数

标签 统计

copy-paste ×1

python ×1

wxpython ×1