Python/TkInter粘贴双重内容(例如a),这是因为按键的缘故

2024-10-03 09:13:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python做了一个简单的记事本。除了剪切/复制/粘贴,所有命令都可以。 它们在这里:

`def AppendSel(e = None):
    d = txt.get(SEL_FIRST,SEL_LAST)
    frm.clipboard_append(d)
def Cut(e = None):
    AppendSel()
    txt.delete(SEL_FIRST, SEL_LAST)
def Paste(e = None):
    clipboard = frm.clipboard_get()
    clipboard = clipboard.replace("\n", "\\n")
    try:
        start = txt.index("sel.first")
        end = txt.index("sel.last")
        txt.delete(start, end)
    except TclError:
        pass
    txt.insert("insert", clipboard)`

当我选择'a',Ctrl+C,backspace,然后Ctrl+V,它粘贴'a''a''a''a'。我的错误在哪里,所以这个小程序可以正常运行?你知道吗

我发现的真正错误:错误在按键中。TkInter检测每一毫秒的压力。我怎样才能禁用它?你知道吗

注:凯文,这两个字符是必要的编码,否则它不接受上传。你知道吗


Tags: txtnonegetindex粘贴def错误delete