python输出文本框_收藏一篇 Python 文本框操作命令

原文地址:https://www.cnblogs.com/onlyfu/archive/2013/03/07/2947473.html

属性(Options)

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(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)

待定

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值