"python tkinter entry" How to get a string before a input cursor in entrybox?
entry.get(0,tk.INSERT)
TypeError: get() takes 1 positional argument but 3 were given
"python tkinter entry" How to get a string before a input cursor in entrybox?
entry.get(0,tk.INSERT)
TypeError: get() takes 1 positional argument but 3 were given
Try this:
import tkinter as tk
def get():
print(entry.get()[:entry.index("insert")])
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="Click me", command=get)
button.pack()
root.mainloop()
It gets the contents of the entry then uses string slicing to get all of the characters before entry.index("insert"), which is the insert cursor's position.
For more info please look at this and this.