当我使用.read()
读取文本文件,然后将文本分配给Tkinterlabel
,并使用.grid(row, column, sticky="W")
将其打包到窗口中时,文本不会与窗口的左侧对齐。代码如下:
import tkinter as tk
instructions_file = open("instructions.txt")
instructions = tk.Tk()
instructions.title("Instructions")
instruction_lbl = tk.Label(
master=instructions,
text=instructions_file.read()
).grid(row=1, column=1, sticky="W")
我检查了几次这段代码,但都不知道出了什么问题sticky="W"
应该将文本与窗口的左侧对齐,但它什么也不做,就好像它根本不在那里一样。有人知道我的代码出了什么问题吗
使用“左对齐”将文本向左对齐,使用“左定位”将整个标签向左对齐。anchor=“w”,justify='left'内部标签创建不在网格中
相关问题 更多 >
编程相关推荐