adding a new line of text in Tk

Fredrik Lundh fredrik at pythonware.com
Mon Mar 27 16:37:53 CEST 2006


Ben Cartwright wrote:

> > w =Label(root, text="Congratulations you have made it this far,just a few more
> > questions then i will be asking you some")
> >
> > The problem i have is where i have started to write some text"Congratulations
> > you have made it this far,just a few more questions then i will be asking you
> > some")
> > I would actually like to add some text but it puts it all on one line.I would
> > like to be able to tell it to start a new line.
>
>
> Just use \n in your string, e.g.:
>
> w = Label(root, text="Line 1\nLine 2\nLine 3")
>
> Or a triple-quoted string will do the trick:
>
> w = Label(root, text="""Line 1
> Line 2
> Line 3""")

you can also use the wraplength option to set a max width for
the label widget:

    w = Label(
        root, text="long paragraph...",
        wraplength=150, justify=LEFT
    )

also see:

    http://effbot.org/tkinterbook/label.htm

</F>






More information about the Python-list mailing list