原文位址: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)
待定