How do I position text in the text_box widger? I've tried something like:
show_both_documents_text_box.insert("1.1", "Document number 1")
show_both_documents_text_box.insert("2.2", "LOREM IPSUMCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC")
show_both_documents_text_box.config(state='disabled')
but it doesn't seem to work. Both of texts are displayed one after one
What I'd like to achievie, is something like this:
Document 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Document 2
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
CodePudding user response:
The index must represent an existing position in the document. If you want text on multiple lines, you must insert newlines ("\n"
) at the appropriate places.
show_both_documents_text_box.insert("end", "Document number 1\n")
show_both_documents_text_box.insert("end", "Lorem ipsum dolor sit amet\n\n")
show_both_documents_text_box.insert("end", "Document number 2\n")
show_both_documents_text_box.insert("end", "Lorem ipsum dolor sit amet\n\n")
If you want the data centered, you can apply a tag with the proper alignment.
show_both_documents_text_box.tag_configure("center", justify="center")
show_both_documents_text_box.insert("end", "Document number 1\n", "center")
show_both_documents_text_box.insert("end", "Lorem ipsum dolor sit amet\n\n", "center")
show_both_documents_text_box.insert("end", "Document number 2\n", "center")
show_both_documents_text_box.insert("end", "Lorem ipsum dolor sit amet\n\n", "center")
CodePudding user response:
You can use the tag justify="center"
to align your text to the center
or the end
your text box.