473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

adding a new line of text in Tk

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
Mar 26 '06 #1
2 22892
nigel 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""")

--Ben

Mar 26 '06 #2
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>

Mar 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
10
by: David | last post by:
Can anyone give me a quick code snippet (that is standards-based) for adding OPTION tags to a SELECT dynamically. I have no problem doing it in IE but I am kind of new to the whole standards world...
3
by: AMD Desktop | last post by:
Hi, I need to add a header to a datagrid. This is the code I am trying to use: Dim dgStaffingReport As New DataGrid Dim dgitem As New DataGridItem(0, 0, ListItemType.Header) Dim mycell...
1
by: Brian Conklin | last post by:
Hello Eneryone, I am having a problem. I have written a little app that will take a text "pipe" delimited file and place all of the values in to an Excel spreadsheet. It works great on any of my...
3
by: John Hughes | last post by:
I'm trying to add a user control to a form via the pages render method and I get the following error : "Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server" ...
6
by: John Salerno | last post by:
Ok, this might look familiar. I'd like to use regular expressions to change this line: self.source += '<p>' + paragraph + '</p>\n\n' to read: self.source += '<p>%s</p>\n\n' % paragraph ...
5
by: Steven Smith | last post by:
Hi, I'm trying to write a simple program to print invoices for people I do work for. I've got a form with textboxes for descriptions and amounts for items, and some code for printing the...
1
by: tonylove42 | last post by:
HI, I have probelm adding, updating and deleteing a record. Here is my code for adding . The error I get is: Operation must use an updateable query. Line 135: MyCmd.ExecuteNonQuery() ...
1
by: superDk | last post by:
Hello, IE6 is adding a large margin between my two containers (container1 & container2) everything works fine in IE7 and Firefox. I've been searching on-line for a fix but I've had no luck. It...
5
by: yuleball | last post by:
I am designing an editor program using rich text box in vb 6.0. I want to add a special box for entering verse or poems so that when I click a button, this box is placed at current position of cursor...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.