In my project I'm trying to add matching parentheses as I type into a tkinter.Text
widget. Basically, when I type (
, the program automatically inserts )
.
The only answer I could find for this same issue is here. I tried all three options the selected answer had, and none worked. The answer is 10 years old so I thought it would have been outdated.
Here is what I have so far. The code works, but the ending-parentheses is inserted before the start-parentheses. (looks like this )(
.). How can I make the ending-parentheses get inserted after the starting one?:
text_box.bind("<(>", lambda n: text_box.insert(float(text_box.index("insert")) + 1, ")"))
It would also help if the ending-parentheses is put after the cursor (to the left of your cursor is (
and to the right is )
Thanks for any answers