0

I am trying to use the destroy command to eliminate a Label, but the command remove only the last character of the text. when I call the function to write data ("w") in the label, it works very good, but if I call the function to destroy it ("d"), just last character is removed. The function is below:

def escreve(texto, oper, pos_x, pos_y):
    global lb
    if oper == "w": 
        lb = Label(janela, text = texto, font = "arial 16")
        lb.grid(row = pos_x, column = pos_y, padx = 2, pady = 2)
    if oper == "d":
        lb.destroy()


Mike
  • 1,107
  • 6
  • 7
  • people why the answer has been deleted? What I made wrong? – Wagner Ideali Feb 26 '20 at 02:07
  • 1
    I can't find an example of `.destroy()` as a string-bound function, or a function on any generic variable outside of, say, [tkinter's .destroy()](https://www.geeksforgeeks.org/destroy-method-in-tkinter-python/). Are you sure you don't want `del lb` instead? – PeptideWitch Feb 26 '20 at 02:12
  • I need to destroy the label, but I think that my fault is that I need to change only the text and not to use the Label complete to do this. I think that the Python is create the new one everytime – Wagner Ideali Feb 26 '20 at 02:15
  • So if I'm guessing right, this function creates a Label class instance and, depending on the `oper` variable, it either modifies the grid variable or deletes the instance. Is that what you're after? – PeptideWitch Feb 26 '20 at 02:18
  • First you have to understand [Event-driven programming](https://stackoverflow.com/a/9343402/7414759) it seems you are stacking `Label` widgets. – stovfl Feb 26 '20 at 11:27

0 Answers0