Search code examples
pythontkinterwidgettkinter-entry

entry.delete(-1) Deletes second to last character in a entry field but I need the last. Python Tkinter


I have a entry widget that when a user clicks a button it executes this code:

entry.delete(-1)

But it removes the second to last character from the entry widget. I need to remove the last character why is this not working?


Solution

  • You may want to try

    entry.delete(len(entry.get())-1)
    

    and see if that does the trick. This dynamically computes the index of the last character of any string in the Entry widget, and at least on Win7 deletes appropriately, from the right side.