Text component of python3.6 tkinter

鸟救山
Release: 2020-05-22 11:23:12
Original
120 people have browsed it

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

## highlightbackground Define the highlight background color when the text control does not receive input focus. It's the bright edge of the text control. highlightcolor The highlightbackground property is similar. It's just the border color of the text control when it gets input focus. highlightthickness The 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
insertbackground Set the color of the text control insertion cursor insertborderwidth Insert 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. insertwidth Sets the width of the insertion cursor. padx Padding in the x-axis direction pady Padding in the y-axis direction Margin relief Specifies the 3D border effect of the text control. The default is flat. The parameters that can be set are: flat, groove, raised, ridge, solid, sunken selectbackground Set the background color of the selected text selectborderwidth Set 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 name Description bbox() 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 text delete(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)

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

Returns the index value of INDEX in the form of line.char. Insert characters at index index position Return all marks values Replace the value between index index1 and index2 with chars search(self, pattern, index) From Start searching for the content of the regular expression at the index position ##tag_add(self, tagName, index1, *args) Add tag tag_bind(self, tagName, sequence, func, add=None) Bind Defining events and unbinding Delete tag Remove specific tags between indexes Create a sub-window at the index position

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!

Related labels:
1
source:php.cn
Statement of this Website
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
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!