Linked Questions

Popular Questions

CSV File display a string input

Asked by At

I have created a Tkinter app to store the data in CSV file. The code as follow:

def add_file():
    global msg
    msg = entry.get()
    print(msg)
    if msg != '':
        listbox_tasks.insert(END, msg)
        entry.delete(0, END)
    else:
        messagebox.showinfo('Info', 'Please Fill In The Entry Box!')

def save_file(msg):
    with open('hello.csv', 'a', newline='') as f:
        writer = csv.writer(f, quotechar='"', quoting=csv.QUOTE_ALL)
        writer.writerow([msg])
    messagebox.showinfo('Info', 'Message Saved!')

scrollbar_tasks = Scrollbar(root)
scrollbar_tasks.pack(side=RIGHT, fill=Y)

listbox_tasks = Listbox(root, yscrollcommand=scrollbar_tasks.set, height=12, width=32, 
                         font=('Helvatica', 18))
listbox_tasks.pack(pady=20)

entry = Entry(label_frame1, font=('Helvatica', 18))
entry.grid(row=0, column=1)

my_create = Button(label_frame2, text='Add File', 
                   font=('Helvatica', 15), command=add_file)
my_create.grid(row=0, column=0, pady=10, padx=10)

my_entry = Button(label_frame2,  text='Save File', bg='green', fg='#ffffff',
                   font=('Helvatica', 15), command=lambda:save_file(msg))
my_entry.grid(row=1, column=0, pady=10, padx=10)

When I enter 1,Apple in entry and clicked save file button, in my CSV file display as "1,Apple" instead of 1,"Apple".

How could I strip out the string?

Related Questions