-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappointment.py
More file actions
126 lines (99 loc) · 4.67 KB
/
Copy pathappointment.py
File metadata and controls
126 lines (99 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# import modules
from tkinter import *
import sqlite3
import tkinter.messagebox
# connect to the databse.
conn = sqlite3.connect('database.db')
# cursor to move around the databse
c = conn.cursor()
# empty list to later append the ids from the database
ids = []
# tkinter window
class Application:
def __init__(self, master):
self.master = master
# creating the frames in the master
self.left = Frame(master, width=800, height=720, bg='lightgreen')
self.left.pack(side=LEFT)
self.right = Frame(master, width=400, height=720, bg='steelblue')
self.right.pack(side=RIGHT)
# labels for the window
self.heading = Label(self.left, text="ABC Hospital Appointments", font=('arial 40 bold'), fg='black', bg='lightgreen')
self.heading.place(x=0, y=0)
# patients name
self.name = Label(self.left, text="Patient's Name", font=('arial 18 bold'), fg='black', bg='lightgreen')
self.name.place(x=0, y=100)
# age
self.age = Label(self.left, text="Age", font=('arial 18 bold'), fg='black', bg='lightgreen')
self.age.place(x=0, y=140)
# gender
self.gender = Label(self.left, text="Gender", font=('arial 18 bold'), fg='black', bg='lightgreen')
self.gender.place(x=0, y=180)
# location
self.location = Label(self.left, text="Location", font=('arial 18 bold'), fg='black', bg='lightgreen')
self.location.place(x=0, y=220)
# appointment time
self.time = Label(self.left, text="Appointment Time", font=('arial 18 bold'), fg='black', bg='lightgreen')
self.time.place(x=0, y=260)
# phone
self.phone = Label(self.left, text="Phone Number", font=('arial 18 bold'), fg='black', bg='lightgreen')
self.phone.place(x=0, y=300)
# Entries for all labels============================================================
self.name_ent = Entry(self.left, width=30)
self.name_ent.place(x=250, y=100)
self.age_ent = Entry(self.left, width=30)
self.age_ent.place(x=250, y=140)
self.gender_ent = Entry(self.left, width=30)
self.gender_ent.place(x=250, y=180)
self.location_ent = Entry(self.left, width=30)
self.location_ent.place(x=250, y=220)
self.time_ent = Entry(self.left, width=30)
self.time_ent.place(x=250, y=260)
self.phone_ent = Entry(self.left, width=30)
self.phone_ent.place(x=250, y=300)
# button to perform a command
self.submit = Button(self.left, text="Add Appointment", width=20, height=2, bg='steelblue', command=self.add_appointment)
self.submit.place(x=300, y=340)
# getting the number of appointments fixed to view in the log
sql2 = "SELECT ID FROM appointments "
self.result = c.execute(sql2)
for self.row in self.result:
self.id = self.row[0]
ids.append(self.id)
# ordering the ids
self.new = sorted(ids)
self.final_id = self.new[len(ids)-1]
# displaying the logs in our right frame
self.logs = Label(self.right, text="Logs", font=('arial 28 bold'), fg='white', bg='steelblue')
self.logs.place(x=0, y=0)
self.box = Text(self.right, width=50, height=40)
self.box.place(x=20, y=60)
self.box.insert(END, "Total Appointments till now : " + str(self.final_id))
# funtion to call when the submit button is clicked
def add_appointment(self):
# getting the user inputs
self.val1 = self.name_ent.get()
self.val2 = self.age_ent.get()
self.val3 = self.gender_ent.get()
self.val4 = self.location_ent.get()
self.val5 = self.time_ent.get()
self.val6 = self.phone_ent.get()
# checking if the user input is empty
if self.val1 == '' or self.val2 == '' or self.val3 == '' or self.val4 == '' or self.val5 == '':
tkinter.messagebox.showinfo("Warning", "Please Fill Up All Boxes")
else:
# now we add to the database
sql = "INSERT INTO 'appointments' (name, age, gender, location, scheduled_time, phone) VALUES(?, ?, ?, ?, ?, ?)"
c.execute(sql, (self.val1, self.val2, self.val3, self.val4, self.val5, self.val6))
conn.commit()
tkinter.messagebox.showinfo("Success", "Appointment for " +str(self.val1) + " has been created" )
self.box.insert(END, 'Appointment fixed for ' + str(self.val1) + ' at ' + str(self.val5))
# creating the object
root = Tk()
b = Application(root)
# resolution of the window
root.geometry("1200x720+0+0")
# preventing the resize feature
root.resizable(False, False)
# end the loop
root.mainloop()