Search code examples
pythontexttkinterundo-redo

Calling a function when undoing or redoing in a Text widget


I know that you can set undo=True for a Text widget, and then press CTRL + Z and CTRL + Y for undo and redo.

But I was wondering if there was a function I could bind to a button or something like that.


Solution

  • The text widget has both an edit_undo() and edit_redo() method, which is what the built-in bindings use. You can call these methods from a button or menu item if you wish.