Label width in tkinter Label width in tkinter tkinter tkinter

Label width in tkinter


height and width define the size of the label in text units when it contains text.Follow @Elchonon Edelson's advice and set size of frame + one small trick:

from tkinter import *root = Tk()def make_label(master, x, y, h, w, *args, **kwargs):    f = Frame(master, height=h, width=w)    f.pack_propagate(0) # don't shrink    f.place(x=x, y=y)    label = Label(f, *args, **kwargs)    label.pack(fill=BOTH, expand=1)    return labelmake_label(root, 10, 10, 10, 40, text='xxx', background='red')make_label(root, 30, 40, 10, 30, text='xxx', background='blue')root.mainloop()