Korak-997
ну ребята извините что я вас всех побеспокоил но я все равно не смог решить свою проблему !!!
ниже я опубликую весь код, который у меня есть в этом файле и используется для этой части моей программы, и надеюсь, что вы сможете найти мою ошибку .
PS: данные добавляются в базу данных как : гггг-ММ-ДД
я тоже пишу запись таким же образом !! так что я думаю, что у вас не должно быть никаких проблем с добавлением данных
вот код, который у меня есть ::
from tkinter import*
from second_win import*
from datetime import datetime
# the function i wrote to create the calculation window
def cal():
cal_win = Toplevel()
cal_win.title("Calculations Window")
cal_win.geometry("600x600")
cal_win.configure(background="black")
global d_f_entry
global d_u_entry
#the function which have to return the sum of working time between two dates
def weekly_cal():
connect = sqlite3.connect('working_time_app.db')
cursor = connect.cursor()
cursor.execute("SELECT sum(fnishing - starting) FROM working_time_app_table WHERE date BETWEEN ? and ? ",
(d_u_entry, d_f_entry))
sum_result = cursor.fetchall()
show_weekly_cal_label = Label(cal_win, text=sum_result, font=("mv boli", 12), fg="white", bg="black")
show_weekly_cal_label.grid(column=3, row=15, columnspan=5)
connect.commit()
connect.close()
#the function which shows a daily calculation ( does not have any effect on the one which do the weekly calculation )
def day_cal():
h_sum = str( float(until_entry.get()) - float(from_entry.get()) )
date_sum = str(date_entry.get())
day_sum = str(day_entry.get())
label_show_sum = Label(cal_win, text=(" you worked " + " "
+ h_sum + "H" + " \n " + "on" + " " + day_sum + " " + date_sum),
bg="black", fg="white", font=("mv boli", 20))
label_show_sum.grid(column=3, row=4, columnspan=5)
#the function i created to show daily data and then be able to calculate and show how many hours someone worked in a day
def cal1():
global date_entry
global day_entry
global from_entry
global until_entry
day_label = Label(cal_win, text="Day", font=("mv boli", 20), fg="white", bg="black")
date_label = Label(cal_win, text="Date", font=("mv boli", 20), fg="white", bg="black")
from_label = Label(cal_win, text="From", font=("mv boli", 20), fg="white", bg="black")
until_label = Label(cal_win, text="Until", font=("mv boli", 20), fg="white", bg="black")
#this buttons shows the calculation of a daily datas ( how many hours of work per in that day )
daily_cal_button = Button(cal_win, text="Show Daily Sum", fg="black", bg="white",
font=("mv boli", 15), command=day_cal, width=15)
#here i created entry boxes so that the datas that i have in the data base each one will be added to its right place
day_entry = Entry(cal_win, width=30)
date_entry = Entry(cal_win, width=30)
from_entry = Entry(cal_win, width=30)
until_entry = Entry(cal_win, width=30)
date_label.grid(column=1, row=2, pady=5)
day_label.grid(column=3, row=2, pady=5)
from_label.grid(column=1, row=3, pady=5)
until_label.grid(column=3, row=3, pady=5)
daily_cal_button.grid(column=1, row=5, pady=5, columnspan=2)
day_entry.grid(column=4, row=2, pady=5)
date_entry.grid(column=2, row=2, pady=5)
from_entry.grid(column=2, row=3, pady=5)
until_entry.grid(column=4, row=3, pady=5)
connect = sqlite3.connect('working_time_app.db')
cursor = connect.cursor()
record_id = id_entry.get()
cursor.execute("SELECT* from working_time_app_table WHERE oid=" + record_id)
records = cursor.fetchall()
connect.commit()
connect.close()
#here this for loop if for inserting the datas into the right entry box
for record in records:
day_entry.insert(0, record[0])
date_entry.insert(0, record[1])
from_entry.insert(0, record[2])
until_entry.insert(0, record[3])
# because that i created these things in the same window as others so i clean the screen with destry and forget function
daily_button.destroy()
monthly_sum_button.grid_forget()
weekly_sum_button.grid_forget()
date_from_entry.grid_forget()
date_until_entry.grid_forget()
until_date_label.grid_forget()
from_date_label.grid_forget()
id_label = Label(cal_win, text="ID", font=("mv boli", 15), fg="white", bg="black")
id_entry = Entry(cal_win, width=30)
id_entry.grid(column=3, row=1, pady=5)
id_label.grid(column=2, row=1, pady=5)
#the button that get you in the daily calculations window
daily_button = Button(cal_win, text="Daily Sum", font=("mv boli", 15),
fg="black", bg="white", width=10, command=cal1)
daily_button.grid(column=3, row=2, columnspan=2)
#this button should show hours of work in the whole month and then the income also
#but yet did not created any function for it ( i want to finish the weekly function first )
monthly_sum_button = Button(cal_win, text="Monthly Sum", fg="black", bg="white",
font=("mv boli", 15), width=15)
#thid button should do the weekly calculation ( which i have a problem with its function !!! )
weekly_sum_button = Button(cal_win, text="Weekly Sum",
fg="black", bg="white",
font=("mv boli", 15), width=15, command=weekly_cal)
monthly_sum_button.grid(column=3, row=7, pady=5, columnspan=2)
weekly_sum_button.grid(column=3, row=8, pady=5, columnspan=2)
from_date_label = Label(cal_win, text="From", font=("mv boli", 15), fg="white", bg="black")
from_date_label.grid(column=2, row=5, pady=5)
#this is the entry box i created which allows the user to enter the begin date
date_from_entry = Entry(cal_win, width=30)
date_from_entry.grid(column=3, row=5, pady=5)
until_date_label = Label(cal_win, text="Until", font=("mv boli", 15), fg="white", bg="black")
until_date_label.grid(column=4, row=5, pady=5)
# this is the entry box i created that allow the user to enter the ending date
date_until_entry = Entry(cal_win, width=30)
date_until_entry.grid(column=5, row=5, pady=5)
#this two variable i created to get the data from the date entry boxes that i have and then use it in the weekly function
#in order to calculate the date in a range of days
d_u_entry = date_until_entry.get()
d_f_entry = date_from_entry.get()
cal_win.mainloop()