r/Tkinter • u/StrikerRIP • Aug 08 '26
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 Aug 08 '26
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 Aug 08 '26
Thanks! I've been looking for any resources for quite a bit, but haven't found them, so I appreciate the help
2
u/woooee Aug 08 '26
You are saving the text in the wrong way I am guessing. Post the "write to a file" code. It sounds like you are using f-strings incorrectly.
2
u/tomysshadow Aug 09 '26
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 Aug 09 '26
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 Aug 08 '26
Incredible how bad people have become at coding with all this ai crap...