1

这是关于来自 python/IDLE 的 Text 小部件方法的帮助内容,名为:dump

 |  dump(self, index1, index2=None, command=None, **kw)
 |      Return the contents of the widget between index1 and index2.
 |      
 |      The type of contents returned in filtered based on the keyword
 |      parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
 |      given and true, then the corresponding items are returned. The result
 |      is a list of triples of the form (key, value, index). If none of the
 |      keywords are true then 'all' is used by default.
 |      
 |      If the 'command' argument is given, it is called once for each element
 |      of the list of triples, with the values of each triple serving as the
 |      arguments to the function. In this case the list is not returned.

我只能完成这项工作(下)。不知道如何为其添加参数。我的意思是“标记”、“标签”、“文本”等。

myText.dump("sel.first","sel.last"):
4

1 回答 1

1

您可以通过将以这些参数命名的关键字参数设置为来添加参数True。它在文档中说明了这一点(重点由我添加):

根据关键字参数过滤返回的内容类型;如果 'all', 'image', 'mark', 'tag', 'text', or 'window'给出且为 true,则返回相应的项目。

例如,要设置tag参数,您可以这样做:

text.dump("1.0", "end", tag=True)

同样,要获取标签和文本信息,您可以这样做:

text.dump("1.0", "end", tag=True, text=True)
于 2020-12-16T04:12:03.070 回答