【问题标题】:Undo, Redo, Copy, Cut tkinter Python撤消、重做、复制、剪切 tkinter Python
【发布时间】:2018-04-12 15:58:03
【问题描述】:

我冒昧地缩短了代码以只适合我的问题我一直试图弄清楚如何在我用 Python 制作的文本编辑器中实现撤消、重做、复制和剪切按钮。我在互联网上看到了一些例子,但我在实现它时遇到了问题。任何帮助将不胜感激!

from tkinter import *
import os
import tkinter
import tkinter.scrolledtext as ScrolledText
from tkinter import Tk, scrolledtext, Menu, filedialog, messagebox, Text, simpledialog, filedialog
import requests
import urllib.request

#Functions
def donothing():
    messagebox.showinfo('Not Implimented', 'This option has not been implimented yet!')

root = Tk()
menu = Menu(root)
root.config(menu=menu)

root.title('Written in Python')
root.minsize(width=100, height=100)
root.geometry('800x500+350+150') #Height, Width, X, Y coordinates of the program

#NotePad
textArea = ScrolledText.ScrolledText(root, width=100, height=100) #Height and width of notepad
textArea.pack()

editMenu = Menu(menu)
menu.add_cascade(label="Edit",menu=editMenu)
editMenu.add_command(label="Undo", command=donothing)
editMenu.add_command(label="Redo", command=donothing)
editMenu.add_command(label="Cut", command=donothing)
editMenu.add_command(label="Copy", command=donothing)

root.mainloop()

【问题讨论】:

  • 欢迎来到 SO。剪切、复制和粘贴看起来与重做和撤消问题不同。在 SO 中搜索 tkinter 问题以在文本小部件中进行选择,并在 tkinter 和/或一般情况下搜索撤消/重做。然后向我们展示您尝试这样做但不起作用的代码。

标签: python tkinter


【解决方案1】:

所以我想通了,这就是我所做的。

def delete():
    notepad.delete(0.0, END)

def redo():
    notepad.edit_redo()

def undo():
    notepad.edit_undo()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多