-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathappointment.py
164 lines (125 loc) · 5.54 KB
/
appointment.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# import modules
try:
# for Python2
from Tkinter import * ## notice capitalized T in Tkinter
except ImportError:
# for Python3
from tkinter import * ## notice lowercase 't' in tkinter here
import tkinter as tk
import sqlite3
import tkinter.messagebox
# connect to the databse.
conn = sqlite3.connect('database.db')
# cursor to move in the database
c = conn.cursor()
# empty list to later appends the ids from the database
ids = []
# tkinter window
class App:
def __init__(self, master):
self.master = master
# creating the format in master
self.left = Frame(master, width=600, height=720, bg='lightblue')
self.left.pack(side = LEFT)
self.right = Frame(master, width=400, height=720, bg='steelblue')
self.right.pack(side = RIGHT)
# heading
self.heading = Label(self.left, text="Enter details", font=('arial 18'), fg='black', bg='lightblue')
self.heading.place(x=220, y=50)
# patient's name
self.name = Label(self.left, text="Patient's Name", font=('arial 12'), fg='black', bg='lightblue')
self.name.place(x=65, y=100)
# age
self.age = Label(self.left, text="Age", font=('arial 12'), fg='black', bg='lightblue')
self.age.place(x=65, y=140)
# gender
self.gender = Label(self.left, text="Gender", font=('arial 12'), fg='black', bg='lightblue')
self.gender.place(x=65, y=180)
# location
self.location = Label(self.left, text="Location", font=('arial 12'), fg='black', bg='lightblue')
self.location.place(x=65, y=220)
# appointment time
self.time = Label(self.left, text="Appointment Time (HH:MM)", font=('arial 12'), fg='black', bg='lightblue')
self.time.place(x=65, y=260)
# phone
self.phone = Label(self.left, text="Phone Number", font=('arial 12'), fg='black', bg='lightblue')
self.phone.place(x=65, y=300)
# Enteries for all labels==============================================================
self.name_ent = Entry(self.left, width=30)
self.name_ent.place(x=275, y=100)
self.age_ent = Entry(self.left, width=30)
self.age_ent.place(x=275, y=140)
# gender list
GenderList = ["Male",
"Female",
"Transgender"]
# Option menu
self.var = tk.StringVar()
self.var.set(GenderList[0])
self.opt = tk.OptionMenu(self.master, self.var, *GenderList)
self.opt.config(width=10, font=('arial', 11))
self.opt.place(x=275, y=180)
# callback method
def callback(*args):
for i in range(len(GenderList)):
if GenderList[i] == self.var.get():
self.gender_ent = GenderList[i]
break
self.var.trace("w", callback)
self.location_ent = Entry(self.left, width=30)
self.location_ent.place(x=275, y=220)
self.time_ent = Entry(self.left, width=30)
self.time_ent.place(x=275, y=260)
self.phone_ent = Entry(self.left, width=30)
self.phone_ent.place(x=275, 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=190, y=350)
# 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 right frame
self.logs = Label(self.right, text="Appointment Log", font=('arial 20 bold'), fg='white', bg='steelblue')
self.logs.place(x=20, y=10)
self.box = Text(self.right, font=('courier 11'), width=40, height=30)
self.box.place(x=20, y=60)
self.box.insert(END, "Total Appointments till now : " + str(self.final_id))
# function to call when the submit button is clicked
def add_appointment(self, event):
# getting the user inputs
self.val1 = self.name_ent.get()
self.val2 = self.age_ent.get()
self.val3 = self.gender_ent
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 == '' or self.val6 == '':
tkinter.messagebox.showwarning("Warning","Please fill up all the details")
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, '\nAppointment fixed for ' + str(self.val1) + ' at ' + str(self.val5))
#creating the object
root = tk.Tk()
b = App(root)
# resolution of the window
root.geometry("1000x620+100+50")
# preventing the resize feature
root.resizable(False, False)
# title of the window
root.title("Add new appointment")
# icon of the application
root.iconphoto(False, tk.PhotoImage(file='resources/icon.png'))
root.bind('<Return>', b.add_appointment)
# end the loop
root.mainloop()