In: Computer Science
Python 3
In the field where it says failure day indicate current date if i run the program today it show todays date and if i run the program tomorrow it show me tomorrows date and so on .
The program is rewriting the product everytime it gets executed i want to add new products as a list in excel
# required library
import tkinter as tk
from tkcalendar import DateEntry
import xlsxwriter
# frame
window = tk.Tk()
window.title("daily logs")
#window.resizable(0,0)
# labels
tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20,
padx=20)
tk.Label(window, text="Products failed").grid(row=1, sticky="W",
pady=20, padx=20)
tk.Label(window, text="Money Lost").grid(row=2, sticky="W",
pady=20, padx=20)
tk.Label(window, text="Failed date").grid(row=3, sticky="W",
pady=20, padx=20)
# entries
barcode = tk.Entry(window)
product = tk.Entry(window)
money = tk.Entry(window)
# arraging
barcode.grid(row=0, column=1)
product.grid(row=1, column=1)
money.grid(row=2, column=1)
cal = DateEntry(window, width=12, year=2019, month=6, day=22,
background='darkblue', foreground='white', borderwidth=2)
cal.grid(row=3, column=1)
# callback function
def cleardate():
barcode.delete(0, 'end')
product.delete(0, 'end')
money.delete(0, 'end')
# callback function
def readValue():
excel_barcode = barcode.get()
excel_product = product.get()
excel_money = money.get()
date = cal._date
print(date)
workbook =
xlsxwriter.Workbook("dailylog.xlsx")
worksheet = workbook.add_worksheet()
worksheet.write("A1", "BARCODE")
worksheet.write("B1", "MONEY")
worksheet.write("C1", "PRODUCT")
worksheet.write("D1", "date")
worksheet.write("A2", excel_barcode)
worksheet.write("B2", excel_money)
worksheet.write("C2", excel_product)
worksheet.write("D2", str(date))
workbook.close()
cleardate() #calls cleardate() function
# button to trigger actions
button = tk.Button(text="SUBMIT", command=readValue).grid(row=4,
pady=20, padx=20)
button = tk.Button(text="CLEAR", command=cleardate).grid(row=4,
column=1, pady=20, padx=20)
window.geometry("500x400")
window.mainloop()
The code is modified as per the requirement
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 05 10:36:32 2019
Description: A program that encrypts a short message using ceasar cipher.
@author: Sagarika Bhar
"""
# required library
import Tkinter as tk
import openpyxl
import xlsxwriter
import os
from tkcalendar import DateEntry
# frame
window = tk.Tk()
window.title("daily logs")
#window.resizable(0,0)
# labels
tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20,
padx=20)
tk.Label(window, text="Products failed").grid(row=1, sticky="W",
pady=20, padx=20)
tk.Label(window, text="Money Lost").grid(row=2, sticky="W",
pady=20, padx=20)
tk.Label(window, text="Failed date").grid(row=3, sticky="W",
pady=20, padx=20)
# entries
barcode = tk.Entry(window)
product = tk.Entry(window)
money = tk.Entry(window)
# arraging
barcode.grid(row=0, column=1)
product.grid(row=1, column=1)
money.grid(row=2, column=1)
cal = DateEntry(window, width=12,background='darkblue',
foreground='white', borderwidth=2)
cal.grid(row=3, column=1)
# callback function
def readValue():
excel_barcode = barcode.get()
excel_product = product.get()
excel_money = money.get()
date = cal.get_date()
print(date)
data=[excel_barcode,excel_money,excel_product,str(date)]
# Call a Workbook() function of openpyxl
# to create a new blank Workbook object
wb = openpyxl.load_workbook('dailylog.xlsx')
# Get workbook active sheet
# from the active attribute
sheet = wb.active
sheet.append(data)
wb.save('dailylog.xlsx')
# callback function
def cleardate():
barcode.delete(0, 'end')
product.delete(0, 'end')
money.delete(0, 'end')
def createworkbook():
workbook = xlsxwriter.Workbook("dailylog.xlsx")
worksheet = workbook.add_worksheet()
worksheet.write("A1", "BARCODE")
worksheet.write("B1", "MONEY")
worksheet.write("C1", "PRODUCT")
worksheet.write("D1", "date")
wb = openpyxl.load_workbook('dailylog.xlsx')
wb.save('dailylog.xlsx')
exists = os.path.isfile('dailylog.xlsx')
if exists:
# button to trigger actions
button = tk.Button(text="SUBMIT", command=readValue).grid(row=4,
pady=20, padx=20)
else:
createworkbook()
button = tk.Button(text="SUBMIT", command=readValue).grid(row=4,
pady=20, padx=20)
button = tk.Button(text="CLEAR", command=cleardate).grid(row=4,
column=1, pady=20, padx=20)
window.geometry("500x400")
window.mainloop()