【发布时间】:2016-08-22 23:17:50
【问题描述】:
我正在使用 Tkinter 在 python 中实现搜索功能,并希望选择它遇到的第一个匹配项。我已经看到了许多创建 tag_config 以突出显示索引范围的背景的示例,但是我想选择文本(与单击第一个索引,然后单击最后一个索引的方式相同)。
到目前为止,我已经获得了我需要选择的区域的开始和结束索引,我只是不知道使用该信息“选择”文本的命令。
我当前的代码(使用突出显示的方法)是:
def search_command():
word = askstring("Search", "Enter word to search")
length = len(str(word))
pos = textPad.search(word, '1.0', stopindex=END)
row, col = pos.split('.')
endlen = int(col) + length
end = row + '.' + str(endlen)
textPad.tag_add("found", pos, end)
“found”标签只是突出显示文本的背景,而不是选择它。
我们将不胜感激找到正确函数的任何帮助。
【问题讨论】:
标签: python-3.x user-interface search tkinter