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

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.

主站蜘蛛池模板: 威远县| 广宗县| 九江县| 嫩江县| 普安县| 苏尼特右旗| 苍南县| 三门县| 兰州市| 宁乡县| 永登县| 靖江市| 昭苏县| 徐州市| 资兴市| 苍南县| 邹城市| 营山县| 成都市| 永平县| 青神县| 平南县| 璧山县| 巴中市| 剑河县| 剑阁县| 高青县| 怀宁县| 柳林县| 呼图壁县| 资源县| 醴陵市| 长海县| 酉阳| 龙陵县| 贡嘎县| 酒泉市| 延长县| 丰都县| 布尔津县| 津市市|