I want to fetch data for a specific period from a MySQL table and print it to an excel file. I am using the DateEntry widget to specify the periods. My code is written below but it is not working.
class PrintbyDate(Tk):
def __init__(self):
super().__init__()
self.maxsize(400, 200)
self.minsize(400, 200)
self.iconbitmap(img_resource_path("chegutuicon.ico"))
self.title("Export Report for a specific date range.")
self.canvas = Canvas(width=1366, height=768, bg='gray')
self.canvas.pack()
a = StringVar()
StartDate=DateEntry(self, date_pattern='YYYY-MM-DD')
StartDate.place(x=200, y=50)
Label(self, text='Select Start Date:', bg='gray', font=('Courier new', 10, 'bold')).place(x=70, y=50)
EndDate=DateEntry(self, date_pattern='YYYY-MM-DD')
EndDate.place(x=200, y=100)
Label(self, text='Select Start Date:', bg='gray', font=('Courier new', 10, 'bold')).place(x=70, y=100)
def ent():
con=connect(user="ngonex",passwd="2007Ngonidzashe",host="localhost",database="complains_database"
)
# Read the data
df=sql.read_sql('select * from client WHERE DateReported is BETWEEN StartDate.get_date() AND EndDate.get_date()', con)
print(df)
#Export the data into excel sheet
df.to_excel('complains_report.xlsx')
messagebox.showinfo("Successful", "Report generated successfully check output folder!")
Button(self, text='Print', width=15, font=('arial', 10),command =ent ).place(x=70, y = 130)