Hey all,
I am working on a calculator program and am using a StringVar() for the Entry widget.
What I need is to delete the last char from the StringVar() when the user hits the
'Backspace' button.

I have everything bound and all, I just don't know what the code is for removing the
last char. I've looked around but I haven't found anything online about how to do it.

Thanks in advance,

- WolfShield

Are you not letting to take care of that? That is whole point of using StringVar. Of course you can slice out the char at insert point. You have read the code of vegaseat and me from code snippets and sticky messages, haven't you? See the advice linked in my signature.

I am a hobbyist programmer.
I have no formal training, nor even a book in Python's case. So, I have not read about
the StringVar() and have no real knowledge of it. If someone could post a link to some
StringVar() documentation, that would be immensely helpful! I've searched but haven't
found anything that describes how to use it.

@tonyjv, I don't mean to be rude to you by posting this, but I do look around before
I post. I just don't know about StringVar() and I haven't found anything on it.
I follow the advice on your link post before I ask a question (except for the code
snippets part most of which are not in tkinter, which is what I use).

- WolfShield

tkinter is written in another language tcl and StringVar is living in the other side. Generally you assign it value or get value from it as whole. Tkinter (tcl interpreter Tk) keeps the variable up to date with the Entry contents and you do not need to touch it. i will experiment litle more myself, but a log of your unsuccesful efforts would help.

While posting I was inspired and have found a way. (eSV = Entry StringVar())

tempV = eSV.get()
tempV = tempV[0:-1]
eSV.set(tempV)

I tried the way before, slightly differently, and it didn't work, so I had kind of
cast the method out. I shouldn't of done that. :)

Anyway, thanks for the info tonyjv. The knowledge will help.

- WolfShield

If

eSV.set(eSV.get()[0:-1])

did not work, it is little strange this works.

Hmm,
I have a lot to learn about compressing code.

- WolfShield

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.