Home > database >  Tkinter Unable to justify text on right
Tkinter Unable to justify text on right

Time:05-24

I have tkinter based chat window where i want to display messages on right side of chat box with help of output

as seen from output window first message is displayed on left side while i justify it on right kindly help me to sort it out thank you

CodePudding user response:

It is because a space character is not inserted with tag 'right' before the first label, so it is not aligned to the right. As "\n " is inserted before subsequent labels, those labels are aligned to the right.

Suggest to insert a space before every label inserted instead of after the "\n":

self.text_box.insert(END, " ", "right")
self.text_box.window_create(END, window=Label( self.text_box, fg="floral white", text=pr1, wraplength=200, font=("Arial", 12), bg="#426CB4", bd=8, justify="left"))
self.text_box.insert(END, "\n")
  • Related