I have an issue where I've created a text widget inside a tkinter Frame that is suppose to center the text on the first line when the user types. It does this, except the first letter they type it justify's it to the left then after a second letter is pressed it justify's to the center as expected.
I would like to know how to fix this so the first line stays centered.
Here is the code I've gotten so far:
import Tkinter as tk
def testing(event=None, text=None):
LineNumber = text.index(tk.INSERT) # returns line number
if "1." in LineNumber:
text.tag_add("center", "1.0", "end")
root = tk.Tk()
F1 = tk.Frame(root, bg="blue", width=300, height=300)
F1.pack()
text = tk.Text(F1, padx=5, pady=10, bg="white")
text.tag_configure("center", justify='center')
text.pack(expand=1, fill="both")
text.bind('<Key>', lambda event: testing(None, text))
root.mainloop()