- 308 名前:デフォルトの名無しさん [2012/01/11(水) 18:03:06.04 ]
- tkinterのテキストボックスを検索してタグを付けたいのすが、下記のコードだと正規表現を使うと、当たり前ですがキーワードの長さが取得出来ません。"(Y|y)ou"は当然7文字カウントしてしまいます。どうしたら検索結果ぴったりにタグが付けられるのか全く思いつきません。
from tkinter import * def search_it(keyword_from,widget): ...if "C" not in widget.mark_names(): ......widget.mark_set("C","1.0") ...try:widget.tag_delete("it") ...except:pass ...keyword=keyword_from.get() ...keyword_length=len(keyword)#正規表現を使うとlengthがおかしなことになる。 ...ini=widget.search(keyword,"C",exact=False,regexp=True) ...end=ini+"+"+str(keyword_length)+"chars" ...widget.tag_add("it",ini,end) ...widget.tag_config("it",foreground="#FF0000",font="arial 18 bold") ...widget.mark_unset("C") ...widget.mark_set("C",end) ...widget.see(ini) root=Tk() ent=Entry(root) ent.pack() btn=Button(root,text="search",command=lambda:search_it(ent,tex)) btn.pack() tex=Text(root) tex.pack() root.mainloop() import 2ch try:2ch.tell_me_a_hint(search_it)#お願いします。 except:pass
|

|