1
votes

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?

1
the diffis the represent the instance of the class like self, but i use a different name :) - Alvin_Sanchez
That's better. Now can you please show what is edit_undo? - Tomerikoo
edit_undo is a built in method within Text widget class here's the information about it - Alvin_Sanchez
but i still dont get anything :( - Alvin_Sanchez
Please see my answer below, but also please read about minimal reproducible example. Your code is still not reproducible. You use self.entry but never define it - Tomerikoo

1 Answers

1
votes

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())