Tkinter Text(文本)
您还可以使用标签和商标一样优雅的结构,找到特定部分的文本,并更改应用到这些领域。此外,你可以嵌入在文本和图像的窗口,因为这个小工具的目的是要处理的平原和格式化文本.
语法:
这里是一个简单的语法来创建这个widget:
w = Text ( master, option, ... )
参数:
master: 这代表了父窗口.
options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.
| Option | Description |
|---|---|
| bg | The default background color of the text widget. |
| bd | The width of the border around the text widget. Default is 2 pixels. |
| cursor | The cursor that will appear when the mouse is over the text widget. |
| exportselection | Normally, text selected within a text widget is exported to be the selection in the window manager. Set exportselection=0 if you don't want that behavior. |
| font | The default font for text inserted into the widget. |
| fg | The color used for text (and bitmaps) within the widget. You can change the color for tagged regions; this option is just the default. |
| height | The height of the widget in lines (not pixels!), measured according to the current font size. |
| highlightbackground | The color of the focus highlight when the text widget does not have focus. |
| highlightcolor | The color of the focus highlight when the text widget has the focus. |
| highlightthickness | The thickness of the focus highlight. Default is 1. Set highlightthickness=0 to suppress display of the focus highlight. |
| insertbackground | The color of the insertion cursor. Default is black. |
| insertborderwidth | Size of the 3-D border around the insertion cursor. Default is 0. |
| insertofftime | The number of milliseconds the insertion cursor is off during its blink cycle. Set this option to zero to suppress blinking. Default is 300. |
| insertontime | The number of milliseconds the insertion cursor is on during its blink cycle. Default is 600. |
| insertwidth | Width of the insertion cursor (its height is determined by the tallest item in its line). Default is 2 pixels. |
| padx | The size of the internal padding added to the left and right of the text area. Default is one pixel. |
| pady | The size of the internal padding added above and below the text area. Default is one pixel. |
| relief | The 3-D appearance of the text widget. Default is relief=SUNKEN. |
| selectbackground | The background color to use displaying selected text. |
| selectborderwidth | The width of the border to use around selected text. |
| spacing1 | This option specifies how much extra vertical space is put above each line of text. If a line wraps, this space is added only before the first line it occupies on the display. Default is 0. |
| spacing2 | This option specifies how much extra vertical space to add between displayed lines of text when a logical line wraps. Default is 0. |
| spacing3 | This option specifies how much extra vertical space is added below each line of text. If a line wraps, this space is added only after the last line it occupies on the display. Default is 0. |
| state | Normally, text widgets respond to keyboard and mouse events; set state=NORMAL to get this behavior. If you set state=DISABLED, the text widget will not respond, and you won't be able to modify its contents programmatically either. |
| tabs | This option controls how tab characters position text. |
| width | The width of the widget in characters (not pixels!), measured according to the current font size. |
| wrap | This option controls the display of lines that are too wide. Set wrap=WORD and it will break the line after the last word that will fit. With the default behavior, wrap=CHAR, any line that gets too long will be broken at any character. |
| xscrollcommand | To make the text widget horizontally scrollable, set this option to the set() method of the horizontal scrollbar. |
| yscrollcommand | To make the text widget vertically scrollable, set this option to the set() method of the vertical scrollbar. |
方法:
文本对象,这些方法:
| Methods & Description |
|---|
| delete(startindex [,endindex]) This method deletes a specific character or a range of text. |
| get(startindex [,endindex]) This method returns a specific character or a range of text. |
| index(index) Returns the absolute value of an index based on the given index. |
| insert(index [,string]...) This method inserts strings at the specified index location. |
| see(index) This method returns true if the text located at the index position is visible. |
文本组件支持三种不同的辅助结构:标记,选项卡,和索引:
标记是使用书签在一个给定的文本两个字符之间的位置。处理标记时,我们可用下列方法:
| Methods & Description | |
|---|---|
| index(mark) Returns the line and column location of a specific mark. |
|
| mark_gravity(mark [,gravity]) Returns the gravity of the given mark. If the second argument is provided, the gravity is set for the given mark. |
|
| mark_names() Returns all marks from the Text widget. |
|
| mark_set(mark, index) Informs a new position to the given mark. |
|
| mark_unset(mark) Removes the given mark from the Text widget. |
标签是用来关联名称的文本,这使得容易修改特定的文本区显示设定的任务的地区。标签也可以用来绑定事件回调到特定范围的文字.
以下是可用的方法处理标签:
| Methods & Description |
|---|
| tag_add(tagname, startindex[,endindex] ...) This method tags either the position defined by startindex, or a range delimited by the positions startindex and endindex. |
| tag_config You can use this method to configure the tag properties, which include, justify(center, left, or right), tabs(this property has the same functionality of the Text widget tabs's property), and underline(used to underline the tagged text). |
| tag_delete(tagname) This method is used to delete and remove a given tag. |
| tag_remove(tagname [,startindex[.endindex]] ...) After applying this method, the given tag is removed from the provided area without deleting the actual tag definition. |
方法:
自行尝试下面的例子:
from Tkinter import * def onclick():
pass root = Tk()
text = Text(root)
text.insert(INSERT, "Hello.....")
text.insert(END, "Bye Bye.....")
text.pack() text.tag_add("here", "1.0", "1.4")
text.tag_add("start", "1.8", "1.13")
text.tag_config("here", background="yellow", foreground="blue")
text.tag_config("start", background="black", foreground="green")
root.mainloop()
这将产生以下结果:

Tkinter Text(文本)的更多相关文章
- tkinter中text文本与scroll滚动条控件(五)
text与scroll控件 import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry("30 ...
- python tkinter Text
"""小白随笔,大佬勿喷""" '''tkinter —— text''' '''可选参数有: background(bg) 文本框背景色: ...
- Python Tkinter Entry(文本框)
Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...
- Python Tkinter Text控件
原文地址: http://blog.csdn.net/bemorequiet/article/details/54743889 这篇博客主要是简单的说一下Tkinter中的Text控件的相关知识. T ...
- Python2.7.3 Tkinter Entry(文本框) 说明
Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor ...
- tkinter学习-文本框
阅读目录 Entry 输入框 Text 文本框 Entry: 说明:输入控件,用于显示简单的文本内容 属性:在输入框中用代码添加和删除内容,同样也是用insert()和delete()方法 from ...
- jquery选中将select下拉框中一项后赋值给text文本框
jquery选中将select下拉框中一项后赋值给text文本框,出现无法将第一个下拉框的value赋值给文本框 因为select默认选中第一项..在选择第一项时,便导致无法激发onchange事件. ...
- placeholder 解决UITextField中placeholder和text文本同时显示的问题
TextField都使用了placeholder属性,但在代码中又设置了text属性,因此ViewController会同时显示placeholder文本和text文本. 这个问题让我彻底崩溃.按道理 ...
- html5与js关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的value点击全选状态onclick="select();"。做购物车页面时会要用到。
关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的点击全选状态onclick="s ...
随机推荐
- 从互联网进化的角度看AI+时代的巨头竞争
今天几乎所有的互联网公司在谈论和布局人工智能,收购相关企业.人工智能和AI+成为当今科技领域最灸手可热的名词,关于什么是AI+,其概念就是用以表达将"人工智能"作为当前行业科技化发 ...
- 构造字典:DictionaryBase类和SortedList类
DictionaryBase 类 msdn对DictionaryBase的文档解释 泛型KeyValuePair类 msdnd对泛型KeyValuePair类的文档解释 SortedList类 RUN ...
- Android studio 添加背景图片问题
问题:下载了JPG格式的图片,Windows下直接改变后缀名,'变为'PNG. 输入 adroid:background"@mipmap/bg" 编译报错!!!老是不行 解答:图片 ...
- java区分绝对路径和相对路径
java区分绝对路径和相对路径 这里要区分的是目录路径 如: /opt/deve/tomcat/bin c:\deve\tomcat\bin 都是绝对目录路径 bin bin/data bin\dat ...
- BZOJ3609 Heoi2014 人人尽说江南好【推理+结论】
BZOJ3609 Heoi2014 人人尽说江南好 Description 小 Z 是一个不折不扣的 ZRP(Zealot Round-game Player,回合制游戏狂热玩家),最近他 想起了小时 ...
- Ubuntu12.04无法使用vim系统剪贴板解决方法
以前在 vim 下工作需要在 vim 和其它的编辑器之间复制东西,使用 Shift + Ctrl + v/c.感觉这样很不方便,今天在网上搜索了以下可以用 “+y/p,但是自己实验怎么也不行,在命令模 ...
- psoc4的capsense总结
psoc4的capsense算是个比较实用的东西,触摸按键,显得有点高大上,呵呵.今天试用了一下,对照着数据手册,现在总结一下. 1,先说原理,官方做文档的时候应该把原理讲一下,不要上来就讲怎么用,怎 ...
- FastAdmin 前端页面传参笔记
FastAdmin 前端页面传参笔记 看到 QQ 群里的小伙伴询问如何传参,然后在社区里找到一笔记帖子 1 还要参考在线文档控制器部分2. 引用 Karson 的回复: 如果我们需要自己在控制器中透传 ...
- 关于tab的切换之共用html页面,而引发的页面跳转错乱问题
在一个项目中的同一个模块中,有多个tab(并且多个tab对应的页面结构完全一样),tab的每次切换,不同tab调用不同的接口,利用一个switch进行判断,根据当前的类型去调用不同的接口,返回不同数据 ...
- apktool重新打包错误
E:\apktool-install-windows-r05-ibot\apktool-install-windows-r05-ibot\.\test_apk_name\res\layout-larg ...