在 tkinter 中查找特定文本位置时使用变量

Using a variable when finding a specific text location in tkinter

所以,我正在尝试为我的 tkinter 文本编辑器实现一个 find_and_replace 选项。我已经设置了我的程序如何在程序中查找文本并且它完美地工作,我唯一的问题是我正在使用一个变量来定位确切的单词所在的位置。

    text.delete(1.other_other, 1.(other_other+other))

1 代表行号,但每当我 运行 程序时,它总是告诉我逗号前有语法错误。 任何想法都是有帮助的。

谢谢:)

索引必须是字符串。 1.other_other 不是字符串。您可以使用 python 的字符串格式来为您提供适当的索引:

start_index = "1.%d" % other_other
end_index = "1.%d" % other_other+other
text.delete(start_index, end_index)