Reputation: 21
"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
Upvotes: 0
Views: 122
Reputation: 7680
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.
Upvotes: 1