-1

I'm creating a GUI and have encountered a small problem. for some reason, I don't want to use labels. I have a Tkinter entry and want to change the text inside with newlines in it. Unfortunately adding '\n' doesn't work. is there any way to add a new line in Tkinter entry?

FinalAnswer =[]
Resultentry.delete(0,"end")
FinalAnswer.append("All Answers are (Kg/m³). The Best Mixure Found is : ")
FinalAnswer.append("Water:" +  str(results[0]) + " Cement: " + str(results[1]) + " Fine Aggregate: " + str(results[2])  + " Course Aggregate: " + str(results[3]))
FinalAnswer.append(" Super Plastizier:" + str(results[4]) + "Air Entaining Agent " + str(results[5])  + " Fly Ash: " + str(results[6]))
FinalAnswer.append(" With the Properties of: Compressive Strenght: " + str(results[7])  + " And 28 day Carbonation of " + str(results[9]) + "mm")
FinalAnswer.append(", RCPT of " + str(results[10]) + "Coulombs" + " and Cost of " + str(results[11]) + "$ With environment damage of " + str(results[12]* 100) + "%")
Resultentry.insert(0,FinalAnswer[0] + '\n' + FinalAnswer[1] + '\n' + FinalAnswer[2] + '\n' + FinalAnswer[3] + '\n' + FinalAnswer[4])

the \n's are not working. I hope there is a way to force the entry to get new lines.

Kshahnazari
  • 135
  • 1
  • 7
  • Read up on [When to use the Entry Widget](http://effbot.org/tkinterbook/entry.htm) and [When to use the Text Widget](http://effbot.org/tkinterbook/text.htm) – stovfl May 16 '20 at 07:42
  • Does this answer your question? [whats-the-difference-between-entry-and-text](https://stackoverflow.com/questions/50194711) – stovfl May 16 '20 at 07:48

1 Answers1

1

A similar question has been answered here

As @stovfl mentioned you need to select the proper widget for your requirement.

You could use the Text widget:

import tkinter as tk

window = tk.Tk()
window.geometry("300x200")

lbl1= tk.Label(text="My results:"  , pady=20)
lbl1.pack()

Answer_pad = tk.Text()
sample=['line 1', 'line 2']
Answer_pad.insert(tk.END, f'{sample[0]}\n{sample[1]}' )
Answer_pad.pack()
window.mainloop()
rush dee
  • 304
  • 1
  • 4
  • 13