Tkinter Text widget is another input widget similar to the Entry widget which accepts multiline user input in a text field. It contains many inbuilt features and functions which helps to configure the default properties of the text widget. However, to add undo/Redo features in the Tkinter text widget, we can use Boolean attributes undo which ensures that the text can be retrieved again.
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Create a Text widget with undo is set text=Text(win, width=60, height=20, undo=True) text.pack() text.insert(END, "Enter anything Here...") win.mainloop()
Run the above code to display a text widget that has Undo/Redo features enabled.
To test the feature, write something in the Text widget and press Ctrl+Z to undo or Ctrl+Y to redo the text.