Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo and redo features in a Tkinter Text widget?

I need to make both a Control + Z and Shift + Control + Z function in a Tkinter Text widget, so that one may undo and redo things.

Does anyone have an idea on how to do it?

like image 607
rectangletangle Avatar asked Jul 02 '10 21:07

rectangletangle


People also ask

How do you redo in tkinter?

The Tkinter Text widget already supports undo with Control + Z and redo with Shift + Control + Z, but you have to enable them on the widget with undo=True .

Is there an undo function in Python?

Most Python commands which affect the underlying state of an object create an undo/redo action which can then be undone or redone through Python or through the Edit > Undo and Redo menu items.

What is the use of undo feature?

To undo an action, press Ctrl + Z. To redo an undone action, press Ctrl + Y. The Undo and Redo features let you remove or repeat single or multiple typing actions, but all actions must be undone or redone in the order you did or undid them – you can't skip actions.

What does Textvariable do in tkinter?

In the case of textvariable , which is mostly used with Entry and Label widgets, it is a variable that will be displayed as text. When the variable changes, the text of the widget changes as well.


2 Answers

The Tkinter Text widget already supports undo with Control + Z and redo with Shift + Control + Z, but you have to enable them on the widget with undo=True. You might also want to use autoseparators=True and maxundo=-1. See this link https://www.tcl.tk/man/tcl8.5/TkCmd/text.htm#M65.

like image 190
IPonder Avatar answered Sep 28 '22 00:09

IPonder


The tkinter Text widget supports undo and redo operations using a stack

At the following link you can find more information:

http://www.tkdocs.com/tutorial/text.html#more

Otherwise you could look at the tkinter or Tk docs for the Text widget and how to create a binding to some keys. The tkinter Text widget function you need is edit_undo.

like image 33
schlenk Avatar answered Sep 28 '22 02:09

schlenk