Python2.7.3 Tkinter Entry(文本框) 說明

Python學習記錄--關於Tkinter Entry(文本框)的選項、方法說明,以及一些示例。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)

刪除文本框裏直接位置值oop

#示例
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)

選中指定索引和光標所在位置以前的值code

#示例
text.selection_adjust(2)  #選中索引爲2和光標全部位置以前的全部值

selection_clear(), select_clear()

清空文本框orm

#示例
text.selection_clear() 

selection_from(index), select_from(index)

待定htm

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)

待定

相關文章
相關標籤/搜索