收藏一篇 Python 文本框操作命令
原文地址:https://www.cnblogs.com/onlyfu/archive/2013/03/07/2947473.html
属性(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)
待定
收藏一篇 Python 文本框操作命令的更多相关文章
- python识别html主要文本框
在抓取网页的时候只想抓取主要的文本框,例如 csdn 中的主要文本框为下图红色框: 抓取的思想是,利用bs4查找所有的div,用正则筛选出每个div里面的中文,找到中文字数最多的div就是属于正文的d ...
- wxpython 支持python语法高亮的自定义文本框控件的代码
在研发闲暇时间,把开发过程中比较重要的一些代码做个珍藏,下面的代码内容是关于wxpython 支持python语法高亮的自定义文本框控件的代码,应该是对大家也有用. import keywordimp ...
- Python Tkinter Entry(文本框)
Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...
- python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python webdriver api-操作富文本框
操作富文本框-就是邮件正文部分,可以选字体啥的 第一种方式: 一般都是在iframe里,要切进去,一般是”html/body”,编辑之后,再切出来,然后再send_keys就完事儿 #encoding ...
- Python Tkinter 文本框(Entry)
Python Tkinter 文本框用来让用户输入一行文本字符串. 你如果需要输入多行文本,可以使用 Text 组件. 你如果需要显示一行或多行文本且不允许用户修改,你可以使用 Label 组件. 语 ...
- 点击Enter键,文本框焦点改变 分类: WinForm 2014-04-15 10:30 223人阅读 评论(0) 收藏
一个例子: 一个简单的 登陆界面,有用户名.密码文本框.登陆按钮. 想要实现的效果是,用户输入用户名之后,点击Enter键进入到下一个文本框,同理,输入完密码之后,登陆按钮获得焦点,再次点击Ente ...
- appium+python 清空文本框EditText的值
清空EditText的自动化脚本编写流程: 前提条件:进入到要删除文本框的页面 1.查找到要删除的文本框,可通过id.name等属性进行查找 2.点击 3.通过get_attribute(" ...
- python tkinter-按钮.标签.文本框、输入框
按钮 无功能按钮 Button的text属性显示按钮上的文本 tkinter.Button(form, text='hello button').pack() 无论怎么变幻窗体大小,永远都在窗体的最上 ...
随机推荐
- 1080 MOOC期终成绩
对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分( ...
- Android开发 --代码布局
Android开发 --代码布局 在线性布局LinearLayout里加入view比较简单,因为属性比较少,布局简单 示例,加入一个TextView LinearLayout layout = (Li ...
- SUSE_LINUX 11 SP3 安装 IBM MQ 7.5
0.环境介绍 mq7.5 suse linux 11 1. 上传安装包 上传安装包到 softWare/CI79IML.tar.gz 2. 安装证书 sh ./mqlicense.sh 输入 1 同意 ...
- POJ - 1850 B - Code
Transmitting and memorizing information is a task that requires different coding systems for the bes ...
- RocketMq源码学习(一) nameService
public class NamesrvStartup { public static Properties properties = null; public static CommandLine ...
- pytest启动浏览器,失败用例截图
1.conftest.py # coding:utf- from selenium import webdriver import pytest driver = None @pytest.mark. ...
- python3自学第二天,模块,三元运算
1.模块的认识. sys模块,os模块等 如何引入模块 import os cmd_res1=os.system("dir") # 执行命令dir,不保存结果 print(cmd_ ...
- linux各种系统下载地址
1.Arch Linux Arch Linux在安装过程中提供了强大的可定制选择,支持你下载和安装自己所需的程序包.虽然这个选择对新手来说没有多大的帮助,但是它确实能够帮助那些使用Arch构建系统和存 ...
- 使用git下载源码及数据文件
初学git,用来下载github上的数据和源代码,具体步骤如下. 1.百度搜索git并下载:本想从github直接下载安装,无奈国外服务器的下载速度太慢,建议国内的直接搜索下载完整安装版. 2.完成g ...
- HDU 6103 17多校6 Kirinriki(双指针维护)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...