2

This is my edited code:

from tkinter import *

class UI:
   def __init__(self):
      self.root = Tk()
      self.text= Text(self.root)
      self.text.pack()
      self.text.bind("<Return>", self.entry.edit_undo)
      self.text.mainloop()

UI()

and when I run it it runs normally but, when diff.node_root.bind() is triggered, it shows an error that says TypeError: edit_undo() takes 1 positional argument but 2 were given. can anybody help me please?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

1

The functions that you pass to bind (event handlers) are expected to take one event argument. edit_undo doesn't take any arguments (except for self that is...).

If you are not interested in the actual event, you can instead pass a function that ignores it, something like:

self.text.bind("<Return>", lambda e: self.entry.edit_undo())
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Yes i've already fix it but, its still show an error `_tkinter.TclError: nothing to undo` – Alvin_Sanchez Sep 23 '20 at 08:28
  • Well with that I can't really help as it depends on the state of your text widget. You will have to make sure this actually works only when there is something to undo – Tomerikoo Sep 23 '20 at 08:35