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

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.

主站蜘蛛池模板: 得荣县| 福鼎市| 成安县| 彝良县| 龙江县| 沂源县| 文山县| 高阳县| 连城县| 南澳县| 张家界市| 台东县| 凉城县| 饶河县| 运城市| 教育| 塔城市| 通城县| 灵璧县| 巴彦淖尔市| 建德市| 营口市| 板桥市| 黄陵县| 老河口市| 武义县| 乐陵市| 陈巴尔虎旗| 呼和浩特市| 合水县| 昭平县| 宝坻区| 沧州市| 天峻县| 阳谷县| 奎屯市| 桐柏县| 康马县| 齐齐哈尔市| 乳源| 拜泉县|