1 #撤销操作 2 from tkinter import * 3 master = Tk() 4 #打开undo按钮 5 text=Text(master,width=30,height=5,undo=True) 6 text.pack() 7 text.insert(INSERT,'I love coding') 8 9 def show(): 10 text.edit_undo() 11 b = Button(master,text='撤销',command=show) 12 b.pack() 13 14 mainloop()