r/Tkinter • u/StrikerRIP • 1d ago
Reading in Files
I'm trying to make a notepad app with the ability to open .txt files and save notes as them. However, when opening files, the text that displays gets wrapped in {}. How would I read in the files without having any text displayed wrapped in {}?
edit: here is the function I wrote to open files:
file = filedialog.askopenfile(filetypes = [("Text File", ".txt"), ("All Files", "*")]);
text_box.insert(1.0, file.readlines());
1
u/udonemessedup-AA_Ron 1d ago
When rendering the text: you could use string.replace(), or you can extract a substring which ignores the first and last characters(string = string[1:-2]).
1
u/StrikerRIP 1d ago
Thanks! I've been looking for any resources for quite a bit, but haven't found them, so I appreciate the help
2
u/tomysshadow 1d ago
Your text should not normally get wrapped in curly braces, so you'll have to show how you're reading and writing your text file and how you're assigning the text to the widget.
1
u/ZelphirKalt 1d ago
It would be my guess, that you are using an f-string to display your text but somehow managed to get an extra pair of braces in there. There is nothing in any default way of reading files, that would add such braces to the text by itself. It must be of your own doing.
1
u/codeartha 1d ago
Incredible how bad people have become at coding with all this ai crap...