Pointer within an entry (tkinter)

0

I'm doing a program that basically by entering a series of numbers, you automatically add a character. My question is if there is any type of pointer in the Entry() of Python since when entering the character externally, the pointer remains in the same position of the last character entered through the keyboard.

The example:

In the Entry() I place 22 and I want you to automatically enter the / character.

In doing so, the pointer stays in front of 22 instead of in front of /

I have tried to give the "focus" to another widget and give the "focus" back to the Entry ()

Is there a method that allows you to handle the pointer within Entry() ?

    
asked by Esteban 10.09.2018 в 17:41
source

1 answer

0

To modify by code the position of the insertion cursor within the Entry (and with it the visible mark of it) you must use the tkinter.Entry.icursor method indicating the index in which you want it to be displayed, if it is at the end of the text simply use the constant tkinter.END .

A simple example:

import tkinter as tk

root = tk.Tk()
root.geometry("600x50")
entry = tk.Entry(root)
entry.pack(expand=True, fill='x')

def agregar_texto():
    entry.insert(tk.END, "Hola Stackoverflow ")
    entry.icursor(tk.END)

btn = tk.Button(root, text="Agregar", command=agregar_texto)
btn.pack()
root.mainloop()

You should simply call the method icursor in the method where you modify the content of Entry immediately after inserting the new text.

    
answered by 10.09.2018 в 17:57