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

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.

主站蜘蛛池模板: 增城市| 灵寿县| 景洪市| 体育| 库尔勒市| 集贤县| 中超| 探索| 固始县| 深州市| 攀枝花市| 涡阳县| 瑞丽市| 丰城市| 乌鲁木齐市| 黔西县| 涟源市| 论坛| 永州市| 同江市| 桃园市| 怀安县| 揭阳市| 宁晋县| 蒙城县| 罗源县| 集安市| 灵璧县| 宜城市| 阳泉市| 长白| 合肥市| 星座| 教育| 威信县| 甘孜县| 鄢陵县| 宝山区| 辽阳市| 五峰| 福鼎市|