One, lable components
The lable component is the label used to output the description on the interface;
1. To cite an example,
#lable Components fromTkinterImport*Root=Tk () root.title ("Yfacesclub")#Create a text lable objecttextlable = Label (root,text="please click to watch again later! ") #text= "I'm sorry! \ n Please click to watch again later! ", JUSTIFY=LEFT,PADX = ten)Textlable.pack (side=Left )#Create an image lable object#instantiate an Image object with PhotoimagePhoto = Photoimage (file="12.gif") imglable= Label (root,image=photo) Imglable.pack (side=Right ) Mainloop ()
2. Use \ n to break the label text
#lable Components fromTkinterImport*Root=Tk () root.title ("Yfacesclub")#Create a text lable objectTextlable =Label (root, Text="I'm sorry! \ n Please click to watch again later! ", JUSTIFY=LEFT,PADX = 10# Aligns the text portion to the left and leaves a certain distance between the horizontal and the border, as long as the justify and PADX options for the lable are set to Textlable.pack (side=Left )#Create an image lable object#instantiate an Image object with PhotoimagePhoto = Photoimage (file="12.gif") imglable= Label (root,image=photo) Imglable.pack (side=Right ) Mainloop ()
Execute the code,
Parameter justify: Alignment of multiline text (Left,right,center)
3. Component parameters
Master formulates the parent window of the control
Anchor the position of the text or image (Bitmap/image) of the label, default to center, value and layout:NW N NE w center e SW S SE
Background (BG) background color;
Foreground (FG) foreground color; borderwidth (BD) border width; width label widths; height tag heights; bitma The built-in bitmap in the P tag, or the option is ignored if the image option is specified. The following bitmaps are valid on all platforms: Error, gray75, gray50, gray25, Gray12, Hourglass, info, questhead,question, and warning. a font font; a picture in an image tag; justify the alignment of multiple lines of text; the text in the TextBox can be used ' \ n ' indicates that line textvariable display text is automatically updated, with Stringvar, etc.
WRAPLENGTH specifies how many widths of text Chinese to start a line break
compound specifies how the text and image (Bitmap/image) are displayed on the label, the default is None, and when the IMAGE/BITMAP is specified, the text is overwritten and only the image is displayed. ( Left: The image is right:Top: Image,bottom: Image,Center: Text overlay on image, set text and image blending mode
For example:
(1) wraplength
Description: Specifies how many widths of text to start a newline label=tkinter.label (root,text='To specify how many units of text Chinese to start a line break', Wraplength=50) (2) Justify Description: Alignment of multiple lines of text in text label=tkinter.label (root,text='abcdefghikjlmnopqrstuvwxyz', Wraplength=50,justify=' Left')
Label=tkinter.label (root,text='abcdefghikjlmnopqrstuvwxyz', Wraplength=50,justify=' Right') Label=tkinter.label (root,text='abcdefghikjlmnopqrstuvwxyz', Wraplength=50, justify='Center') (3) Anchor Description: Text or image (bitmap/image) at the label's location. Default to center value and layout: NW N NE w Center e SW S Selabel=tkinter.label (root,text='Abcdefghikjlmnopqrstu', Wraplength=50,width=30,height=10, BG='Blue', fg='Red', anchor='NW') (4) Bitmap Description: Displays the built-in bitmap. If the image option is specified, this option is ignored. The following bitmaps are valid on all platforms: Error, gray75, gray50, gray25, Gray12, Hourglass, info, questhead,question, and warning. Label=tkinter.label (root,bitmap='Error') (5) FG BG Description: Set foreground and background colors label=tkinter.label (root,text='helloworld!', fg='Red', bg='Blue') (A). Use the color name Red Green Blue Yellow lightblue ...
(b). Use#RRGGBB label = label (ROOT,FG = ' red ', bg = ' #FF00FF ', Text = ' Hello I am Tkinter ')Specifies that the background color is crimson
(c). In addition, TK supports OS-related color values such as Windows Support Systemactiveborder, Systemactivecaption, Systemappworkspace, Systembackground , ..... (6) Width height Description: Set width and height label=tkinter.label (root,text='helloworld!', FG='Red', bg='Blue', Width=50,height=10) (7) Compound Description: Specify text and image (bitmap/image) is displayed on the label, the default is None, when the specified image/when bitmap, the text will be overwritten, showing only the image. Values you can use: Left: Image right: Top of Image: Image on top bottom: Image in Center: text overlay on image label=tkinter.label (root,text='Error', bitmap='Error', compound=' Left')
GUI Library's Tkinter component (ii)