Home  >  Article  >  Backend Development  >  Text component of python3.6 tkinter

Text component of python3.6 tkinter

鸟救山
鸟救山Original
2020-05-21 20:52:54177browse

As a standard interface for Python GUI programming, tkinter has a very rich window control. This article introduces its Text component in detail.

Text component is a component that displays and processes multi-line text and has a very flexible application method.

The properties are divided into two categories, including STANDARD OPTIONS and WIDGET-SPECIFIC OPTIONS
. The basic description table is shown

## highlightbackgroundDefine the highlight background color when the text control does not receive input focus. It's the bright edge of the text control. highlightcolorThe highlightbackground property is similar. It's just the border color of the text control when it gets input focus. highlightthicknessThe border width of the text control when it gets input focus. Generally 1-2 pixels.
STANDARD attribute value Description
background Background color
borderwidth The border width of the text control. The default is 1-2 pixels.
cursor The cursor of the text control. The default is a character insertion cursor (usually an "I-beam" type cursor)
exportselection Whether to allow copying content to the clipboard
font Font settings and size
foreground Foreground color
insertbackgroundSet the color of the text control insertion cursor insertborderwidthInsert cursor border width. If it is a non-zero value, the cursor will use a RAISED border. These two properties control the insert cursor flashing effect. It is the time when the insertion cursor appears and disappears. The unit is milliseconds. insertwidthSets the width of the insertion cursor. padxPadding in the x-axis directionpadyPadding in the y-axis direction MarginreliefSpecifies the 3D border effect of the text control. The default is flat. The parameters that can be set are: flat, groove, raised, ridge, solid, sunkenselectbackgroundSet the background color of the selected textselectborderwidthSet the border width of the selected area.
insertofftime

insertontime

setgrid boolean type. When True, the window can be maximized and the entire Text control can be displayed.
takefocus Defines whether the Tab key can be used to move the input focus to the control.

xscrollcommand

yscrollcommand

Associate the scroll bar with the text control and handle the scroll bar action. The scroll bars correspond to horizontal or vertical scroll bars respectively.
WIDGET-SPECIFICWindow Properties Description
autoseparators The space between words. The default value is 1
height The height of the text control. The default is 24 lines.
maxundo Maximum number of Undo. The default is 0.
spacing1 Spacing before paragraph.
spacing2 Line spacing.
spacing3 Spacing after paragraph.
state Define the state of the text control. There are two states: NORMAL and DISABLED
tabs Define the movement distance when pressing the Tab key.
undo Enable undo/redo function.
width Define the width of the text control, the unit is the number of characters.
wrap Define how to wrap the content of the text control

Methods of the Text basic class:

##Method nameDescriptionbbox()Return a tuple describing the position and size (x, y, width, height) ##compare(index1, op, index2)count(self, index1, index2)debug(self, boolean=None)According to BOOLEAN, check the consistency of the B-Tree within the textdelete(self, index1, index2=None)dlineinfo(self, index)##edit(self, * args)get(self, index1, index2=None)image_create(self, index, cnf={}, **kw)



Return a logical comparison result

Calculate the number of related things between two indexes quantity.


Delete the characters between INDEX1 and INDEX2 (not included)

Return tuple (x, y, width, height, baseline)
This method controls the undo mechanism and
the modified flag.

Returns the value between index INDEX1 to INDEX2 (exclusive)
Create an embedded image at the index INDEX position.
##index(self, index)Returns the index value of INDEX in the form of line.char. Insert characters at index index positionReturn all marks valuesReplace the value between index index1 and index2 with charssearch(self, pattern, index)From Start searching for the content of the regular expression at the index position##tag_add(self, tagName, index1, *args)Add tagtag_bind(self, tagName, sequence, func, add=None)Bind Defining events and unbindingDelete tagRemove specific tags between indexesCreate a sub-window at the index position

Application example of Text component.

One is a simple basic application

from tkinter import *

class init_window():
def __init__(self):
self.tk = Tk ()
self.window_attritions()
def window_attritions(self):
self.tk.title('Text component learning')
self.init_data_text = Text(self.tk)
self.init_data_text.pack()
def show():
print('hello')
if __name__ == "__main__":
win = init_window()
win.tk. mainloop()

Text component of python3.6 tkinter

The second is to insert components

button = Button(win.init_data_text,text='Insert button in text',command=show)
win.init_data_text.window_create(INSERT,window=button)

Text component of python3.6 tkinter

The third is to insert pictures

win.init_data_text.image_create(END, image=PhotoImage(file='1.gif'))

It can be seen from the above introduction that the index value of the Text component has many applications. The following introduces the types of index values


insert(self, index, chars, *args)


mark_names(self)

##replace(self, index1, index2, chars, *args)




tag_unbind(self, tagName, sequence, funcid=None)


tag_delete(self, *tagNames)

tag_remove( self, tagName, index1, index2=None)

window_create(self, index, cnf={}, **kw)

##window coordinate("@x,y")Window positioning
Index Type Description
line.column Row/Column
line.end End of a line
INSERT Cursor position
END End of text
user-defined marks Custom marks
user-defined tags("tag.first", "tag.last")

The above is the detailed content of Text component of python3.6 tkinter. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn