简体   繁体   English

将文本对齐到 tkinter 中的标签顶部

[英]Justify text to the top of label in tkinter

in my code every time I press enter while typing on a entry widget the text on the entry is printed on a label below it but the text is always in the middle of the label.在我的代码中,每次在条目小部件上键入时按 Enter 时,条目上的文本都会打印在其下方的标签上,但文本始终位于标签的中间。 is there a way to make it print on the top?有没有办法让它打印在顶部?

像这样

from tkinter import *

root = Tk()
root.state('zoomed')

def AddList(event):
    de = dataInput.get()

    d = dataList['text'] + de + "\n"
    dataList.config(text=d)   
    dataInput.delete('0', 'end')

dataLabel = Label(root, width=4, text="Dados").grid(column=0, row=0)
dataInput = Entry(root,width=4)
dataInput.bind('<Return>', AddList)
dataInput.grid(column=0, row=1)
dataList = Label(root, text="", width=4, height=43, bg='#8c8c8c')
dataList.grid(column=0, row=2, sticky=NS)

root.mainloop()

Yes there is a way:是的,有一种方法:

By setting anchor='n' , you force the text to be on the top.通过设置anchor='n' ,您可以强制文本位于顶部。

dataList = Label(root, text="", width=4, height=43, bg='#8c8c8c',anchor='n')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM