Where can I find the documentation of this method?
I found only this http://effbot.org/tkinterbook/text.htm The search method allows you to search for text. You can search for an exact match (default), or use a Tcl-style regular expression (call with the regexp option set to true).
What does "Tcl-style regular expression" mean?
I also have a question on my code: why self._testo.tag_add("search", pos, "%s + %sc" (pos, countVar.get()))
returns TypeError: 'str' object is not callable
Thanks in advance
def _trova(self):
t1 = tkinter.Toplevel(self._finestra)
def t():
s = e.get()
start = "1.0"
while True:
countVar = tkinter.StringVar()
pos = self._testo.search(s, start, stopindex="end",count=countVar)
if not pos:
break
self._testo.tag_config("search", background="yellow")
self._testo.tag_add("search", pos, "%s + %sc" (pos, countVar.get()))
start = pos + "+1c"
e= tkinter.Entry(t1).grid(row=0, column=1)
ok = tkinter.Button(t1, text="OK", command= t).grid(row=0, column=2)
Where can I find the documentation of this method?
The canonical documentation is in the tcl/tk documentation here: http://tcl.tk/man/tcl8.5/TkCmd/text.htm#M120 It assumes you are writing in tcl rather than python, but it's fairly simple to translate it into python. The python docs give a good introduction to how to do that. See Mapping basic tk into tkinter
What does "Tcl-style regular expression" mean?
Tkinter is a thin wrapper around a tcl interpreter. Tcl's regular expression syntax is subtly different than Python's. By "tcl-style regular expression", it means that it follows the regular expression syntax described in the re_syntax man page of the tcl project.
I also have a question on my code: why self._testo.tag_add("search", pos, "%s + %sc" (pos, countVar.get())) returns TypeError: 'str' object is not callable
You get the error because you are trying to call a string as if it were a function (in essence, you are doing "foo"()
. This is the offending section of code:
"%s + %sc" (pos, countVar.get())
You seem to have left out a %
between "%s + %sc"
and (pos, countVar.get())
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.