dkol
dkol

Reputation: 27

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. is there a way to make it print on the top?

Like this

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()

Upvotes: 1

Views: 1746

Answers (1)

user15801675
user15801675

Reputation:

Yes there is a way:

By setting anchor='n', you force the text to be on the top.

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

Upvotes: 5

Related Questions