Python3 Tkinter 实例教学 (八)标签Label 设置换行宽度

Python3 Tkinter 实例教学 (八)标签Label 设置换行宽度

本节介绍标签设置文本换行宽度

Label 作为一个最常用的控件,能够展示一些文本或者图片或者文本和图片的组合使用

构造方法:

Label(父对象, text=“标签内容”, wraplength=40)
wraplength:换行宽度 单位 像素

代码实例:

# -*- coding:utf8 -*-

from tkinter import *

root = Tk()
root.title("Label Demo")
root.geometry("300x150")

label = Label(root, text='a a a a a a a a a', fg="red", bg="yellow",
              height=3, width=30,
              anchor=NW, wraplength=40)  # 换行宽度40像素
label.pack()

root.mainloop()

运行结果:

在这里插入图片描述


版权声明:本文为sniperzxl原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。