Python2.7.3 Tkinter Entry(文本框) 说明
Python学习记录--关于Tkinter Entry(文本框)的选项、方法说明,以及一些示例。
属性(Options)
- background(bg)
- borderwidth(bd)
- cursor
- exportselection
- font
- foreground(fg)
- highlightbackground
- highlightcolor
- highlightthickness
- insertbackground
- insertborderwidth
- insertofftime
- insertontime
- insertwidth
- justify
- relief
- selectbackground
- selectborderwidth
- selectforeground
- show
- state
- takefocus
- textvariable
- width
- xscrollcommand
background(bg)
- Type: color
- 说明:文本框的背景颜色
#示例
from Tkinter import * top = Tk() text = Entry(top, background = 'red')
text.pack() mainloop()
borderwidth(bd)
- Type: distance
- 说明:文本框边框宽度
#示例
text = Entry(top, borderwidth = 3)
cursor
- Type: cursor
- 待定
exportselection
- Type: flag
- 待定
font
- Type: font
- 说明:文字字体。值是一个元祖,font = ('字体','字号','粗细')
#示例
text = Entry(top, font = ('Helvetica', '14', 'bold')
foreground
- Type: color
- 说明:文字颜色。值为颜色或为颜色代码,如:'red','#ff0000'
#示例
text = Entry(top, foreground = 'red') #正确
text = Entry(top, foreground = '#ff0000') #正确
text = Entry(top, foreground = 'ff0000') #错误,必须加上#号
highlightbackground
- Type: color
- 说明:文本框高亮边框颜色,当文本框未获取焦点时显示
- 条件:highlightthickness设置有值
#示例
text = Entry(top, highlightbackground = 'red', hightlightthickness = 1)
highlightcolor
- Type: color
- 说明:文本框高亮边框颜色,当文本框获取焦点时显示
- 条件:highlightthickness设置有值
#示例
text = Entry(top, highlightcolor = 'red', hightlightthickness = 1)
highlightthickness
- Type: distance
- 说明:文本框高亮边框宽度。(官网上说有默认值1或2,但如果不设置,实际上没有值,可能和操作系统有关系)
#示例
text = Entry(top, highlightcolor = 'red', hightlightthickness = 1)
insertbackground
- Type: color
- 说明:文本框光标的颜色
#示例
text = Entry(top, insertbackground = 'red')
insertborderwidth
- Type: distance
- 说明:文本框光标的宽度。(有问题,官网未有说明,待定)
#示例
text = Entry(top, insertborderwidth = 3)
insertofftime
- Type: int
- 说明:文本框光标闪烁时,消失持续时间,单位:毫秒
#示例
text = Entry(top, insertofftime = 50)
insertontime
- Type: int
- 说明:文本框光标闪烁时,显示持续时间,单位:毫秒
#示例
text = Entry(top, insertontime = 50)
insertwidth
- Type: int
- 说明:文本框光标宽度
#示例
text = Entry(top, insertwidth = 3)
justify
- Type: const
- 待定
relief
- Type: const
- 说明:文本框风格,如凹陷、凸起,值有:flat/sunken/raised/groove/ridge
#示例
text = Entry(top, relief = 'sunken')
selectbackground
- Type: color
- 说明:选中文字的背景颜色
#示例
text = Entry(top, selectbackground = 'red')
text = Entry(top, selectbackground = '#ff0000')
selectborderwidth
- Type: int
- 说明:选中文字的背景边框宽度
#示例
text = Entry(top, selectborderwidth = 3)
selectforeground
- Type: color
- 说明:选中文字的颜色
#示例
text = Entry(top, selectforeground = 'red')
text = Entry(top, selectforeground = '#ff0000')
show
- Type: character
- 说明:指定文本框内容显示为字符,值随意,满足字符即可。如密码可以将值设为*
#示例
text = Entry(top, show = '*')
state
- Type: const
- 说明:文框状态,分为只读和可写,值为:normal/disabled
#示例
text = Entry(top, state = 'normal') #可操作
text = Entry(top, state = 'disabled') #不可操作
takefocus
- Type: flag
- 说明:是否能用TAB键来获取焦点,默认是可以获得
#示例
待定
textvariable
- Type: variable
- 说明:文本框的值,是一个StringVar()对象
#示例
default_value = StringVar()
default_value.set('This is a default value')
text = Entry(top, textvariable = default_value)
width
- Type: int
- 说明:文本框宽度
#示例
text = Entry(top, width = 50)
xscrollcommand
- Type: callback
- 说明:回调函数
#示例
def callback():
#code text = Entry(top, command = callback)
方法(Methods)
- insert
- delete
- icursor
- get
- index
- selection_adjust, select_adjust
- selection_clear, select_clear
- selection_from, select_from
- selection_present, select_present
- selection_range, select_range
- selection_to, select_to
- scan_mark
- scan_dragto
- xview
- xview_moveto, xview_scroll
insert(index, text)
向文本框中插入值,index:插入位置,text:插入值
#示例
text.insert(0, '内容一') #在文本框开始位置插入“内容一”
text.insert(10, '内容二') #在文本框第10个索引位置插入“内容二”
text.insert(END, '内容三') #在文本框末尾插入“内容三”
delete(index), delete(from, to)
删除文本框里直接位置值
#示例
text.delete(10) #删除索引值为10的值
text.delete(10, 20) #删除索引值从10到20之前的值
text.insert(0, END) #删除所有值
icursor(index)
将光标移动到指定索引位置,只有当文框获取焦点后成立
#示例
text.icursor(10) #移动光标到索引为10的位置
get()
获取文件框的值
#示例
text.get() #返回文本框的值
index(index)
返回指定的索引值
#示例
text.index(2)
selection_adjust(index), select_adjust(index)
选中指定索引和光标所在位置之前的值
#示例
text.selection_adjust(2) #选中索引为2和光标所有位置之前的所有值
selection_clear(), select_clear()
清空文本框
#示例
text.selection_clear()
selection_from(index), select_from(index)
待定
selection_range(start, end), select_range(start, end)
选中指定索引之前的值,start必须比end小
#示例
text.selection_range(2, 10) #选中索引为2和10之前的所有值
selection_to(index), select_to(index)
选中指定索引与光标之间的值(感觉和selection_adjust差不多)
#示例
text.selection_to(2) #选中索引为2和所光标所在位置之前的值
scan_mark(x)
待定
scan_dragto(x)
待定
xview(x)
待定
Python2.7.3 Tkinter Entry(文本框) 说明的更多相关文章
- Python Tkinter Entry(文本框)
Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...
- tkinter学习-文本框
阅读目录 Entry 输入框 Text 文本框 Entry: 说明:输入控件,用于显示简单的文本内容 属性:在输入框中用代码添加和删除内容,同样也是用insert()和delete()方法 from ...
- Tkinter--Text文本框样例
#-*- coding:utf-8 -*- """ Text 文本框样例 实现功能有:Ctrl+a全选文本, 竖向滚动条,横向滚动条(不自动换行) 自动缩放 有谁知道全选 ...
- Python Tkinter 文本框(Entry)
Python Tkinter 文本框用来让用户输入一行文本字符串. 你如果需要输入多行文本,可以使用 Text 组件. 你如果需要显示一行或多行文本且不允许用户修改,你可以使用 Label 组件. 语 ...
- 给tkinter文本框添加右键菜单
给tkinter文本框添加右键菜单 需求:直接右键点击使用tkinter创建的文本框是不会弹出菜单的.我们需要实现右键点击tkinter框架下的Entry对象.Text对象后弹出右键菜单可复制.粘贴和 ...
- tkinter基础-输入框、文本框
本节内容 了解输入框.文本框的使用方法 利用1制作简易界面 首先明确上面由几个元素组成:该界面由界面标题,输入框.两个按钮.文本框组成. 该界面我们需要实现的功能: 在输入框中输入文字,点击inser ...
- Tkinter 之Text文本框标签
一.参数说明 语法 作用 t=tk.Text()t.insert(END,'插入的文本信息') INSERT:光标的插入点CURRENT:鼠标的当前位置所对应的字符位置END:这个Textbuffer ...
- Java+Selenium向文本框输入内容以后模仿键盘的"ENTRY"
在自动化测试中我们避免不了要模仿一些键盘上按钮的操作,普通的字母,数字,特殊符号,这些都是很简单的,有时候我们也会模仿"SHIFT","ALT","C ...
- python tkinter-按钮.标签.文本框、输入框
按钮 无功能按钮 Button的text属性显示按钮上的文本 tkinter.Button(form, text='hello button').pack() 无论怎么变幻窗体大小,永远都在窗体的最上 ...
随机推荐
- Jetty与Tomcat综合比较
Jetty基本架构 Jetty目前的是一个比较被看好的 Servlet 引擎,它的架构比较简单,也是一个可扩展性和非常灵活的应用服务器.它有一个基本数据模型,这个数据模型就是 Handler(处理器) ...
- Qt快速入门学习笔记(基础篇)
本文基于Qter开源社区论坛版主yafeilinux编写的<Qt快速入门系列教程目录>,网址:http://bbs.qter.org/forum.php?mod=viewthread&am ...
- HUAS 1477 经营与开发(贪心)
考虑DP,令dp[i][j][k]当前在第i个星球,用了j次维修,k次开采后所获得的最大价值.复杂度为O(n^3).超时 如果我们发现,对于初始时能力值为w所能产生的最大价值y,初始时能力值为1所能产 ...
- 【bzoj4326】[NOIP2015]运输计划 二分答案+LCA
题目描述 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航道建立在两个星球之间,这 n−1 条航道连通了 L 国的所有星球.小 P 掌管一家物流公司, 该 ...
- 原生JS表单序列化
// 表单序列化,IE9+ HTMLFormElement.prototype.serialize = function() { var form = this; // 表单数据 var arrFor ...
- [Leetcode] word search 单词查询
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- logrotate配置和使用
logrotate是linux自带的日志管理工具.服务器如果不对日志进行滚动操作,单个日志文件的增长速度极快,不利于日志查找和问题定位.而logrotate能够自动完成日志的截断.压缩和滚动操作. 安 ...
- bzoj 4725 [POI2017]Reprezentacje ró?nicowe 暴力
[POI2017]Reprezentacje ró?nicowe Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 141 Solved: 67[Sub ...
- 手脱ASProtect v1.2(无Stolen Code)
1.载入PEID ASProtect v1.2 2.载入OD > 01C04200 push 跑跑赛道.0042C001 ; //入口处 C3 retn AA stos byte ptr es: ...