tkintertk-toolkit

How to examine tkinter.Text undo stack?


Tk documentation talks about undo stack, but doesn't mention whether it's possible to inspect it directly.

I'd like to show Undo command as inactive when undo stack is exhausted. Is keeping track of undo-s and redo-s my only chance, or is there a way to ask tk whether the stack is empty?


Solution

  • There is no way to explicitly examine the undo stack. However, you might be able to use the modified flag to serve a similar purpose.

    From the official tk documentation:

    The undo mechanism is also linked to the modified flag. This means that undoing or redoing changes can take a modified text widget back to the unmodified state or vice versa. The modified flag will be set automatically to the appropriate state. This automatic coupling does not work when the modified flag has been set by the user, until the flag has been reset again.