Tkinter / Python: Error deleting a text from a canvas and wanting to write a different one

0

I have created a "main" window with a canvas in which I load an image and a line of text from an entry Entry. When I delete the text of the canvas and the Entry with the function canvas.delete(tag_del_texto) and entry.delete(0, 'end') and want to write another I get the following error:

  

command = lambda: text1 (main)) TypeError: 'int' object is not callable

texto1(main) is the function to create the text, main is the name of the window.

I have searched for information about this error, but the examples are based on mathematical functions and not objects.

The corresponding part of the code is:

# Creo el texto donde etxt1 es el nombre del Entry:

def texto1():
    global texto1
    try:
        texto1 = canvas.create_text(cw/2, 30, text=etxt1.get(), anchor=CENTER, font=ft, fill="white", tags="tx1")
    except:
        pass

# Borro el texto con la siguiente función:

def borrar1(main):
    canvas.delete("tx1") # Esto borra el texto del canvas
    etxt1.delete(0, 'end') # Esto borra el texto del Entry

But wanting to write something again in the Entry and create it in the canvas gives me the error already described above.

I've tried with the canvas.delete('all') method, but it still gives the same error and it also erases the image and I do not want to.

The update.idletasks() or canvas.forget() methods also do nothing in this case.

I've read that the destroy method, on the other hand, completely eliminates the widget and can no longer be used again.

What is the reason for the error?

    
asked by Toño 05.12.2016 в 00:03
source

1 answer

0

A possible reason is that it is not advisable to call the variables and functions with the same name, for example you use:

def texto1(): 
    global texto1
    
answered by 05.12.2016 / 01:20
source