-1
import tkinter as to
window = tk.Tk()
window.geometry('340x110')

def final():
   for i in field.get():
      answer = tk.Label(text= chr(ord(i)+2))
      answer.pack()

text = tk.Label(text="String Encrypt", font=(30))
text.place(x=100)

text2 = tk.Label(text="Enter The Word/Sentence: ")
field = tk.Entry(width='30')
text2.place(x=0, y=30)
field.place(x=150,y=33)

but = tk.Button(command=final, text="Encrypt")
but.place(x=140, y=60)

window.mainloop()

This is the code. Outputs are coming in new line for every iteration. How can we get in the same line??

  • First you have to understand [Event-driven programming](https://stackoverflow.com/a/9343402/7414759) – stovfl Apr 08 '20 at 07:59

1 Answers1

0

From what I can see for every character in field.get() you are creating a new label (with only one character at a time) and then packing that straight to the window.

You would want to perform all your encryption algorithm on the entire string first, and then add one new label with the whole string:

def final():
    result = ''
    for i in field.get():
        result += chr(ord(i)+2)
    answer = tk.Label(text=result)
    answer.pack()
dwb
  • 2,136
  • 13
  • 27