Python Tkinter Entry (text box)

Source: Internet
Author: User
Tags border color pack

Python Learning Records-options for Tkinter Entry (text boxes), method descriptions, and some examples.

Properties (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
    • Description: The background color of the text box
#示例from Tkinter Import *top = Tk () Text = Entry (top, background = ' red ') Text.pack () Mainloop ()
BorderWidth (BD)
    • Type:distance
    • Description: Text box Border width
#示例text = Entry (top, borderwidth = 3)
Cursor
    • Type:cursor
    • Pending
Exportselection
    • Type:flag
    • Pending
Font
    • Type:font
    • Description: Text font. The value is a meta-ancestor, font = (' font ', ' font size ', ' thickness ')
#示例text = Entry (top, Font = (' Helvetica ', ' + ', ' bold ')
Foreground
    • Type:color
    • Description: Text color. value is color or color code, such as: ' Red ', ' #ff0000 '
#示例text = Entry (top, foreground = ' red ')  #正确text = Entry (top, foreground = ' #ff0000 ')  #正确text = Entry (Top, Foregro und = ' ff0000 ') #错误, you must add the # number
Highlightbackground
    • Type:color
    • Description: The text box highlights the border color, which is displayed when the text box does not get focus
    • Condition: highlightthickness Set a value
#示例text = Entry (top, highlightbackground = ' red ', hightlightthickness = 1)
HighlightColor
    • Type:color
    • Description: Text box highlight border color, display when text box gets focus
    • Condition: highlightthickness Set a value
#示例text = Entry (top, HighlightColor = ' red ', hightlightthickness = 1)
Highlightthickness
    • Type:distance
    • Description: The text box highlights the width of the border. (The official web said there is a default value of 1 or 2, but if not set, there is actually no value, may be related to the operating system)
#示例text = Entry (top, HighlightColor = ' red ', hightlightthickness = 1)
Insertbackground
    • Type:color
    • Description: The color of the text box cursor
#示例text = Entry (top, insertbackground = ' red ')
Insertborderwidth
    • Type:distance
    • Description: The width of the text box cursor. (There is a problem, the official website does not have the description, TBD)
#示例text = Entry (top, insertborderwidth = 3)
Insertofftime
    • Type:int
    • Description: When the text box cursor blinks, the vanishing duration, in milliseconds
#示例text = Entry (top, insertofftime = 50)
Insertontime
    • Type:int
    • Description: Display duration, in milliseconds, when the text box cursor blinks
#示例text = Entry (top, insertontime = 50)
Insertwidth
    • Type:int
    • Description: text box cursor width
#示例text = Entry (top, insertwidth = 3)
Justify
    • Type:const
    • Pending
Relief
    • Type:const
    • Description: text box style, such as concave, convex, values are: Flat/sunken/raised/groove/ridge
#示例text = Entry (top, relief = ' sunken ')
Selectbackground
    • Type:color
    • Description: The background color of the selected text
#示例text = Entry (top, selectbackground = ' red ') Text = Entry (top, Selectbackground = ' #ff0000 ')
Selectborderwidth
    • Type:int
    • Description: The width of the background border of the selected text
#示例text = Entry (top, selectborderwidth = 3)
Selectforeground
    • Type:color
    • Description: The color of the selected text
#示例text = Entry (top, selectforeground = ' red ') Text = Entry (top, Selectforeground = ' #ff0000 ')
Show
    • Type:character
    • Description: Specifies that the content of the text box is displayed as a character, and that the value is arbitrary. If the password can set the value to *
#示例text = Entry (top, show = ' * ')
State
    • Type:const
    • Description: Text box state, divided into read-only and writable, the value is: normal/disabled
#示例text = Entry (top, state = ' normal ')  #可操作text = Entry (top, state = ' disabled ')  #不可操作
TakeFocus
    • Type:flag
    • Note: If you can use the TAB key to get focus, the default is to get
#示例待定
Textvariable
    • Type:variable
    • Description: The value of the text box, which is a stringvar () object
#示例default_value = Stringvar () default_value.set (' This is a default value ') Text = Entry (top, textvariable = Default_value)
Width
    • Type:int
    • Description: Text box width
#示例text = Entry (top, Width = 50)
Xscrollcommand
    • Type:callback
    • Description: Callback function
#示例def callback (): #codetext = Entry (top, command = callback)
Method (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)

Insert a value into a text box, index: Insert position, text: Insert value

#示例text. Insert (0, ' content one ')  #在文本框开始位置插入 "content One" Text.insert (10, ' content two ')  #在文本框第10个索引位置插入 "Content two" Text.insert (END, ' content three ')  #在文本框末尾插入 "content three"
Delete (index), delete (from, to)

Delete the value of the direct position in the text box

#示例text. Delete  #删除索引值为10的值text. Delete  #删除索引值从10到20之前的值text. Insert (0, END)  #删除所有值
ICursor (Index)

Moves the cursor to the specified index position only when the frame gets the focus

#示例text. ICursor (#移动光标到索引为10的位置)  
Get ()

Gets the value of the file box

#示例text. Get ()  #返回文本框的值
Index (Index)

Returns the specified index value

#示例text. Index (2)  
Selection_adjust (index), Select_adjust (index)

Select the value before the specified index and cursor position

#示例text. Selection_adjust (2)  #选中索引为2和光标所有位置之前的所有值
Selection_clear (), Select_clear ()

Empty text box

Selection_from (index), Select_from (index)

Pending

Selection_range (start, end), Select_range (Start, end)

Select the value before the specified index, start must be smaller than end

Selection_to (index), select_to (index)

Select the value between the specified index and the cursor (feel and selection_adjust are the same)

#示例text. Selection_to (2) #选中索引为2和所光标所在位置之前的值
Scan_mark (x)

Pending

Scan_dragto (x)

Pending

Xview (x)

Pending

Here is an example of a text box

Python Tkinter uses entry as a text box input, binds data to a text box by textvariable, and then uses the Get function to get the content. If you want enter to get the content, you need to bind <Return> event with the following code:

1  fromTkinterImport*2 defRtnkey (event=None):3     Print(E.get ())4Root =Tk ()5E =Stringvar ()6Entry = entry (root, validate='Key', Textvariable=e, width=50)7 Entry.pack ()8Entry.bind ('<Return>', Rtnkey)9Root.title ('test Enter to get text box contents')TenRoot.mainloop ()

Python Tkinter Entry (text box)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.