官术网_书友最值得收藏!

Tags

Tags are used to annotate text with an identification string that can then be used to manipulate the tagged text. Tkinter has a built-in tag called SEL, which is automatically applied to the selected text. In addition to SEL, you can define your own tags. A text range can be associated with multiple tags, and the same tag can be used for many different text ranges.

Here are some examples of tagging:

my_text.tag_add('sel', '1.0', 'end') # add SEL tag from start(1.0) to end
my_text.tag_add('danger', "insert linestart", "insert lineend+1c")
my_text.tag_remove('danger', 1.0, "end")
my_text.tag_config('danger', background=red)
my_text.tag_config('outdated', overstrike=1)

You can specify the visual style for a given tag with tag_config, using options such as background (color), bgstipple (bitmap), borderwidth (distance), fgstipple (bitmap), font (font), foreground (color), justify (constant), lmargin1 (distance), lmargin2 (distance), offset (distance), overstrike
(flag), relief (constant), rmargin (distance), spacing1 (distance), tabs (string), underline (flag), and wrap (constant).

For a complete reference about text indexing and tagging, type the following command into the Python interactive shell:

>>> import Tkinter
>>> help(Tkinter.Text)

Equipped with a basic understanding of indexing and tagging, let's implement some more features in the code editor.

主站蜘蛛池模板: 昌平区| 遂川县| 洮南市| 满城县| 宽甸| 贵阳市| 兴国县| 沧源| 汝阳县| 玉溪市| 大田县| 荃湾区| 莲花县| 忻城县| 安新县| 梅河口市| 荥经县| 乐昌市| 莱西市| 太谷县| 鲁山县| 图片| 电白县| 建阳市| 台北市| 兴海县| 松阳县| 周至县| 辰溪县| 松桃| 孝昌县| 祁连县| 象州县| 贞丰县| 唐山市| 茌平县| 桐柏县| 绥宁县| 双鸭山市| 双桥区| 云龙县|