0

I am creating a code editor and I get a minimap with help of this https://stackoverflow.com/a/71895218/18364950

But I having facing some problem with it that is whenever I attached it with my editor area(Text widget) my undo function is not working actually cursor moves back but the recent work is not removing as all undo function working If you can solve this problem please help me to solve my problem

please help

this is my code

import tkinter as tk
class TextPeer(tk.Text):
    """A peer of an existing text widget"""
    count = 0
    def __init__(self, master, cnf={}, **kw):
        TextPeer.count += 1
        parent = master.master
        peerName = "peer-{}".format(TextPeer.count)
        if str(parent) == ".":
            peerPath = ".{}".format(peerName)
        else:
            peerPath = "{}.{}".format(parent, peerName)

        # Create the peer
        master.tk.call(master, 'peer', 'create', peerPath, *self._options(cnf, kw))

        # Create the tkinter widget based on the peer
        # We can't call tk.Text.__init__ because it will try to
        # create a new text widget. Instead, we want to use
        # the peer widget that has already been created.
        tk.BaseWidget._setup(self, parent, {'name': peerName})

root = tk.Tk()

editor = tk.Text(root,font=("JetBrains Mono",15),undo=True)
editor.pack(side=tk.LEFT,expand=True,fill=tk.BOTH)
minimap = TextPeer(editor,font=("JetBrains Mono",4),state="disabled")
minimap.pack(side=tk.RIGHT,fill=tk.Y)



root.mainloop()

this is what I am creating:- enter image description here

Coder
  • 92
  • 11
  • 1
    This question says that your undo function isn't working, but there is no undo function in the code. – Bryan Oakley Apr 27 '22 at 13:53
  • sir I have update the code ,actually this is not a real code my real code is too long that's why I have created a short code just before posting this question please sir help me to solve this problem in my real code I have use undo = True in text widget but still I am unable to undo my recent work – Coder Apr 27 '22 at 13:58
  • Related: https://stackoverflow.com/questions/3169344/undo-and-redo-features-in-a-tkinter-text-widget and https://tkdocs.com/tutorial/text.html#more suggest that the undo=True might be sufficient, but I haven't looked at those in detail. Has @coder ? – Sarah Messer Apr 27 '22 at 14:01
  • @SarahMesser Sir, Can you tell me how create a separator function for undo and redo – Coder Apr 27 '22 at 14:10
  • I've never done it, so I can't give you much help, but this tutorial looks like it should be straightforward: https://www.tutorialspoint.com/undo-and-redo-features-in-a-tkinter-text-widget Confirm that works locally, then gradually convert your code to look more like the real code until you find which step causes the problem. Also note the "Redo" key there is Ctrl-Y, not Ctrl-Shift-Z. – Sarah Messer Apr 27 '22 at 15:35
  • @SarahMesser Sir, In this tutorial website talk about undo = True and I know about it and I have used it in my code this is not work with minimap. if I attach my text widget with minimap undo = True not working else it's working correctly – Coder Apr 27 '22 at 15:54
  • @BryanOakley Sir, The minimap I am using in my code is created by you So I am sure that you can solve it please help me – Coder Apr 27 '22 at 15:56

0 Answers0