adding a new line of text in Tk

N

nigel

Hello i have been working on an interactive programme,i wish to use a small
amount of Tk.Which i have taken from a tutorial.
from Tkinter import *
root = Tk()
w =Label(root, text="Congratulations you have made it this far,just a few more
questions then i will be asking you some")
w.pack()
root.mainloop()

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.
can any one tell me how to do this please
Thanks nige
 
B

Ben Cartwright

nigel said:
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""")

--Ben
 
F

Fredrik Lundh

Ben said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,049
Members
48,769
Latest member
Clifft

Latest Threads

Top