Why does tkinter add in more quotes than what is in the input string?

38 Views Asked by At

Let me start by saying that I am very new to Tkinter.

I want to take input typed by a user from a text box and write to a file in Tkinter. I am using the get() method on the box. I have gotten it to work, but the input breaks when I use double quotes. Single quotes work fine though.

Here is an example of what I am doing:

#example of the code used to create the text box using python and tkinter
text_box = tk.Text(main_window, width=50, height=15, background="white")
text_box.pack()

#this is an example of what happens when we want to gather the data from the box
text_box.get("1.0", tk.END)

let us assume this it in the box: He said "That is my dog"

When I take this phrase from the box and write it to a file, in my case I am using CSV, it adds a bunch of extra double quotes.

Here is what the output looks like:

"He said ""That is my dog""

I need to preserve the original string, with the double quotes exactly as it is typed by the user. I am really confused as to why the extra quotes are added but it does not add them with single quotes.

1

There are 1 best solutions below

0
Elzie On

As stated by the comments on the question, the problem was with my using a CSV writer and how it treated double quotes. I just ended up using the default way to write to files in Python to write the file but still use the CSV module for reading the file. Thank you and sorry for my ignorance lol