【发布时间】:2015-06-01 16:18:08
【问题描述】:
我一直在尝试在我的 Tkinter GUI 上进行按钮检查,以将输入的文本搜索到特定单词的文本小部件中并使其显示为红色,我已经使用以下代码成功地做到了这一点:
list_of_words = ["foo", "bar`enter code here`"]
def check():
global counter
text.tag_remove('found', '1.0', END)
idx = '1.0'
x = 0
while True:
idx = text.search(list_of_words[x], idx, nocase=1, stopindex=END)
if not idx: break
lastidx = '%s+%dc' % (idx, len(list_of_words[x]))
text.tag_add('found', idx, lastidx)
idx = lastidx
text.tag_config('found', foreground='red')
counter += 1
print counter
但是,我需要能够在输入中搜索 list_of_words 列表中的所有单词并将它们全部显示为红色。 有没有办法做到这一点?
【问题讨论】:
标签: python list python-2.7 tkinter