Why does “/n” adds to my input - Tkinter, Python

I didn’t understand why does “/n” is every time adds into the input.
This is unacceptable for my system with file scanning, as I enter a file name without this ending, but it is added and makes it impossible to select that particular file, as there are no files with that ending.

Repl link:


For the photo example, I pressed the scan button without entering anything, but the ending was automatically added. I checked, file = what I entered and when printing This variable ending is not present, it is strictly added when trying to scan the file. If, on the other hand, you enter the file path in the field and then scan it, nothing happens, as the above strange ending is added to the file.

Try calling .strip() on the input, that should remove the trailing newline.

whee = input("Type something: ")

Try casting it to an str first and then call .strip() or you could try replacing it .replace('\\n', '')


Replace wouldn’t work because it isn’t “/n” in the variable.

Then where are you seeing /n

It is only in the error.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.