Why does a black circle appear instead of the backspace when trying to display an Entry '\b' ?

Code:

 if key == 'BS': calc_entry.insert(END, '\b') 

Here is a picture

2 answers 2

Something like this can be implemented in a slightly different way.

 import tkinter def backspace(): entry_text.delete(len(entry_text.get())-1) root = tkinter.Tk() entry_text = tkinter.Entry(root) entry_text.insert(0, '1234567890') entry_text.pack() bs = tkinter.Button(root, text='BS', command=backspace) bs.pack() root.mainloop() 
  • This was my fallback. I thought it could be easier. Thanks for the help - Alexander Zavalishin

To delete a character before the cursor position (as the backspace key does), you can use the 'insert' position:

 #!/usr/bin/env python3 import tkinter.ttk root = tkinter.Tk() entry = tkinter.ttk.Entry(width=30) entry.insert(0, "press BS to emulate <Backspace> key") entry.pack() tkinter.ttk.Button( text="BS", command=lambda: entry.delete(entry.index(tkinter.INSERT) - 1)).pack() root.mainloop() 
  • Thank. Everything works fine. Did not know about index (INSERT). - Alexander Zavalishin
  • @Alexander Zavalishin index ('insert') returns the position of the cursor. - jfs