Unable to extract data from Text widget in Tkinter, Python. However, it works fine for the Entry widgets that are in the code.

My purpose is to take paragraph input from the user and then add the data to a CSV file and subsequently generate a prescription using Photoshop.

Here is the code:

main.py

import abc
import csv, datetime
from tkinter import *
from tkinter import ttk
now=datetime.datetime.now().strftime("%d-%m-%Y")

def DataAdder2CSV():
    global edate, eSNO, eage, egender, ename, ePID, econtact, ecomp, eallergy, ehistory, eR
    a=edate.get()
    b=eSNO.get()
    c=eage.get()
    d=egender.get()
    e=ename.get()
    f=ePID.get()
    g=econtact.get()
    data=[a,b,c,d,e,f,g,ecomp, eallergy, ehistory, eR]
    print(data)
    
    file=open("Patient_Data.csv","a", newline="")
    writer=csv.writer(file, delimiter=",")

    writer.writerow(data)

    file.close()
    
def PrescGen():
    pass
root=Tk()
root.config(bg="#add8e6")

megaF=LabelFrame(root,bg="#add8e6", borderwidth=0)
megaF.pack()

greet=Label(megaF,text="Prescription Maker", bg="#add8e6", fg="black", font="LucidaConsole 30").pack(pady=20)

dateF=Frame(megaF, padx=10, pady=10, bg="#c3dde6")
dateF.pack()

date=Label(dateF,text="Date:", bg="#c3dde6").grid(row=0,column=0)

edate=Entry(dateF, width=10)
edate.insert(0,now)
edate.grid(row=0, column=1)

mainL=Frame(root,borderwidth=0, padx=10, pady=10, bg="#c3dde6")
mainL.pack(pady=20, padx=40)

PDlf=Frame(mainL, padx=10, pady=13, bg="#c3dde6")
PDlf.grid(row=0, column=0, sticky=NW)

sno=Label(PDlf,text="Sno:", bg="#c3dde6").grid(row=0,column=0)
eSNO=Entry(PDlf, width=3)
eSNO.grid(row=0, column=1)

age=Label(PDlf,text="Age:", bg="#c3dde6").grid(row=1,column=0)
eage=Entry(PDlf, width=3)
eage.grid(row=1, column=1, pady=10)

gender=Label(PDlf,text="Gender:", bg="#c3dde6").grid(row=2,column=0)
egender=Entry(PDlf, width=3)
egender.grid(row=2, column=1)

name=Label(PDlf,text="Name:", bg="#c3dde6").grid(row=0,column=3)
ename=Entry(PDlf, width=15)
ename.grid(row=0, column=4)

Pid=Label(PDlf,text="PatientID:", bg="#c3dde6").grid(row=1,column=3)
ePID=Entry(PDlf, width=15)
ePID.grid(row=1, column=4, pady=10)

contact=Label(PDlf,text="Contact:", bg="#c3dde6").grid(row=2,column=3)
econtact=Entry(PDlf, width=15)
econtact.grid(row=2, column=4)

blank=Label(PDlf,text="         ", bg="#c3dde6").grid(row=1,column=2)

contentLF=LabelFrame(mainL, padx=10, pady=10, bg="#c3dde6", borderwidth=0)
contentLF.grid(row=0, column=2, sticky=SE)
#Never gonna give you up, never gonna let you down
blank=Label(PDlf,text="         ", bg="#c3dde6").grid(row=0,column=2)

complaint=Label(contentLF,text="Complaint:", bg="#c3dde6").grid(row=0,column=1)
ecomp=Text(contentLF, width=50, height=3).grid(row=0, column=2)

allergy=Label(contentLF,text="Allergy:", bg="#c3dde6").grid(row=1,column=1)
eallergy=Text(contentLF, width=50, height=2)
eallergy.grid(row=1, column=2, pady=10)

history=Label(contentLF,text="History:", bg="#c3dde6").grid(row=2,column=1)
ehistory=Text(contentLF, width=50, height=5)
ehistory.grid(row=2, column=2)

R=Label(contentLF,text="Diagnosis:", bg="#c3dde6").grid(row=3,column=1)
eR=Text(contentLF, width=50, height=12)
eR.grid(row=3, column=2, pady=10)

buttF=LabelFrame(mainL, bg="#c3dde6", borderwidth=0)
buttF.grid(row=4, column=2, sticky=E)
genPres=Button(buttF,text="Generate Prescription", bg="#ff80b9", command=PrescGen).grid(row=0, column=0, padx=10, sticky=E)

csvAdd=Button(buttF,text="Add to Database", bg="#49ff9a", command=DataAdder2CSV).grid(row=0, column=1,padx=10, sticky=E)

pic=Frame(mainL, padx=10, pady=15, bg="#c3dde6")
pic.grid(row=1, column=0, sticky=NW)

root.title("Prescription Maker")
root.state("zoomed")

root.mainloop()

Here is the output:

Beautigul GUI

Here is the CSV file where I extracted all the data to:

The things happening after Content tab are due to the fact that the data is in the form of Text widget and not Entry widget.

How do I take paragraph input from the user and add the data to the CSV file (Tkinter)?

0

There are 0 best solutions below