Python tkinter -- Chapter 18 Text of Canvas Control

18.2.21 create_text(position, options)
creates a text object at the position (x, y) specified by position:
(1) position: coordinates (x, y)
(2) options: the specific meaning of the options:

options meaning
activefill When the mouse passes over the text object, the color of the text
activestipple When the mouse passes over the text object, the filled bitmap
anchor Specify the relative position of the text in the position parameter, which can be N, NE, E, SE, S, SW, W, NW, or CENTER to position (EWSN stands for East, West, North, South, Up North, Down South, Left West, Right East). The default value is CENTER
disabledfill When the state of the text object is DISABLED, the color of the text
disabledstipple When the state of the text object is DISABLED. bitmap filled with text
fill Specifies the color of the text
fon t specifies the font, size and other information of the text
justify Specifies the alignment for multi-line text, the values ​​that can be used for this option are: LEFT (default), CENTER and RIGHT
offset Specify the offset to fill the bitmap, the value of this option can be: "x,y", "#x,y", N, NE, E, SE, S, SW, W, NW, CENTER
state Specifies the state of the text, which can be NORMAL, DISABLED (do not respond to events) and HIDDEN (hidden). The default value is NORMAL
stipple Specify the bitmap to fill in the text, the default value is an empty string, which means solid
tags Add a label to the created text object
text Specifies what the text object displays
width If this option is specified, text will automatically break at this width. If this option is not specified, the width of the text object is equal to the length of the longest line of text
18.2.21.1 activefill
The text color when the mouse passes over the created text object.
import tkinter as tk
root=tk.Tk()
root.geometry('320x240')
b1=tk.Canvas(root)
text=b1.create_text(50,50,text='文本对象',activefill='red')
b1.pack()
root.mainloop()

Result:
insert image description here
18.2.21.2 activestipple
sets the populated bitmap. But just the text disappears, the bitmap is not filled.
18.2.21.3 How to place the anchor
text at the specified coordinates (x, y), there are the following methods:
(1) N: the coordinates of the top middle point of the text object are (x, y)
(2) S: the bottom middle point of the text object The coordinates are (x, y)
(3) E: the coordinates of the middle point on the right side of the text object are (x, y)
(4) W: the coordinates of the middle point on the left side of the text object are (x, y)
(5) NE: The coordinates of the upper right corner of the text object are (x, y)
(6) NW: the coordinates of the upper left corner of the text object are (x, y)
(7) SE: the coordinates of the lower right corner of the text object are (x, y)
(8) SW : The coordinates of the lower left corner of the text object are (x, y)
(9) CENTER: The coordinates of the middle point of the text object are (x, y)

import tkinter as tk
root=tk.Tk()
root.geometry('320x240')
b1=tk.Canvas(root)
t1=b1.create_text(100,50,text='王',
                  anchor='e',font=('宋体',50,))
t2=b1.create_text(100,50,text='田',
                  anchor='w',font=('宋体',50,))
b1.pack()
root.mainloop()

Result:
insert image description here
Description: 2 text objects are created, the coordinate points are both (100,50), you can see that one is on the left and the other is on the right. This is the role of the anchor.
18.2.21.4 disabledfill
When the state of the text object is tk.DISABLED, the color of the text.

import tkinter as tk
root=tk.Tk()
root.geometry('320x240')
def state():
    b1.itemconfigure(text,state=tk.DISABLED)
b2=tk.Button(root,text='Disabled',command=state)
b2.pack()
b1=tk.Canvas(root)
text=b1.create_text(160,40,text='文本对象',
                    disabledfill='red')
b1.pack()
root.mainloop()

Result:
insert image description here
18.2.21.5 disabledstipple
fills the bitmap when the state of the text object is tk.DISABLED. But only the text disappears, and the bitmap is not filled.
18.2.21.6 fill
sets the color of the text object.
18.2.21.7 font
Specifies the font of the text object. See Section 3.3.3.
18.2.21.8 justify
Specifies the alignment of the text object's wrapping display. See the relevant instructions in Chapter Four.
18.2.21.9 offset
The offset method of filling the bitmap. doesn't work.
18.2.21.10 state
defines the state of the text. There are three kinds: NORMAL, DISABLED and HIDDEN
18.2.21.11 stipple
specifies the shading of filling. doesn't work.
18.2.21.12 tags
Specifies tags for text objects. It can also be specified by other methods.
18.2.21.13 width
Defines the width of the text object.

Guess you like

Origin blog.csdn.net/weixin_42272768/article/details/100873388