0
我正在Python 3.4和Tkinter中创建一个简单的文本编辑器。此刻,我被卡在find
功能上。突出显示Tkinter中的某些字符
我可以找到成功的字符,但我不知道如何突出显示它们。我试过没有成功的标记方法,误差:
str object has no attribute 'tag_add'.
这里是我的查找功能代码:
def find(): # is called when the user clicks a menu item
findin = tksd.askstring('Find', 'String to find:')
contentsfind = editArea.get(1.0, 'end-1c') # editArea is a scrolledtext area
findcount = 0
for x in contentsfind:
if x == findin:
findcount += 1
print('find - found ' + str(findcount) + ' of ' + findin)
if findcount == 0:
nonefound = ('No matches for ' + findin)
tkmb.showinfo('No matches found', nonefound)
print('find - found 0 of ' + findin)
用户输入文本成scrolledtext领域,我想强调的匹配该滚动文本区域上的字符串。
我该如何去做这件事?
我怎么会去的功能删除高亮显示? –
@le_wofl:http://effbot.org/tkinterbook/text.htm#Tkinter.Text.tag_remove-method –