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 –