from tkinter import *
win = Tk()
win.title("逻辑网")
win.iconbitmap('../image/icon.ico')
win.geometry('400x300')
# 创建一个文本控件
# width 一行可见的字符数;height 显示的行数
text = Text(win, width=50, height=20, undo=True, autoseparators=False)
text.grid()
# INSERT 光标处插入;END 末尾处插入
text.insert(INSERT, '你很穷!')
# 定义撤销和恢复方法,调用edit_undo()和 edit_redo()方法
def backout():
text.edit_undo()
def regain():
text.edit_redo()
# 定义撤销和恢复按钮
Button(win, text='撤销', command=backout).grid(row=3, column=0, sticky="w", padx=10, pady=5)
Button(win, text='恢复', command=regain).grid(row=3, column=0, sticky="e", padx=10, pady=5)
win.mainloop()