[Python] How do I use Tkinter to create line-wrapped text that fills the width of the window?

Discussão em 'Python' iniciado por Stack, Agosto 11, 2025.

  1. Stack

    Stack Membro Participativo

    The Label widget doesn't line-wrap. The Message widget will line-wrap text, but forces it to be roughly square. Here's an example:

    from Tkinter import *

    root = Tk()
    root.title("hello")

    Message(root, text=48*'xxxxx ').grid(row=0, column=0, columnspan=3)

    Label(root, text='Name:').grid(row=1, column=0)
    Entry(root, width=50).grid(row=1, column=1)
    Button(root, text="?").grid(row=1, column=2)

    Button(root, text="Left").grid(row=2, column=0)
    Button(root, text="Center").grid(row=2, column=1)
    Button(root, text="Right").grid(row=2, column=2)

    root.mainloop()


    I know that I can use aspect=700 to change the shape, but hard-coding numbers like that is what I'm trying to avoid.

    Continue reading...

Compartilhe esta Página