【发布时间】:2023-01-22 23:37:56
【问题描述】:
我试图使用该代码块来对齐标签 topright 或 bottomleft-like sides 但 pack 方法不允许两个参数...
看我的代码:
import tkinter
class guigui:
def __init__(self):
self.main=tkinter.Tk()
self.label11=tkinter.Label(self.main, text="label text 1")
self.label2=tkinter.Label(self.main, text="label text 2")
self.label1.pack(side="right")
self.label2.pack(side="bottom")
tkinter.mainloop()
if __name__=='__main__':
agui=guigui()
我想将文本 2 对齐到右下角,所以我尝试这样做:
self.label2.pack(side="right")
self.label2.pack(side="bottom")
但它没有用。该块的第二行已执行,但第一行始终被忽略。
到处都写着 pack() 方法只允许左下右下顶部,好吧但是如果我想在交叉区域对齐标签文本我该怎么办?
【问题讨论】:
-
试试
.pack(side="bottom", anchor="e")。
标签: python user-interface tkinter label alignment