Home > Back-end >  Tkinter entry.get adding a line after the value for some reason
Tkinter entry.get adding a line after the value for some reason

Time:09-26

So this is my code:

name = entry0.get()
name = str(name)
print(f"pls give {name} all")

and for some reason this is the output: (assuming the name was Dany) "pls give Dany" "all" whatever text comes after the name that's from entry0 gets printed in another line and if sent in an application, another message.

Why?

CodePudding user response:

Without the rest of context its hard to deduce what the root issue is. I'm going to assume your output looks like:

pls give Dany
all

If this is the case, it's because the name variable has a new line character ('\n') appended at the end of it. You can use the python strip method to remove the new line before its printed.

print(f"pls give {name.strip()} all")
  • Related