如何在 Tkinter Label 中将文本左对齐?
Tkinter Label 窗口小部件可以使用anchor 属性进行对齐。为了计算小部件的适应间距和对齐,锚点将以更好的方式提供帮助。锚点提供了多个选项,例如 N、W、S、E、NW、NE。SW、SE,可以在包管理器本身中对其进行定义。
示例
在以下示例中,我们将通过向“w”方向添加 anchor 属性将应用程序的 Label 文本左对齐。
#Import the required library
from tkinter import*
#Create an instance of tkinter frame
win= Tk()
#Set the geometry
win.geometry("750x250")
#Create a Label Widget
Label(win, text= "New Line Text", font= ('Helvetica 15 underline'),
background="gray74").pack(pady=20, side= TOP, anchor="w")
win.mainloop()输出
运行以上代码将使文本标签小部件向左对齐。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP