-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_front_iti.py
252 lines (197 loc) · 8.77 KB
/
final_front_iti.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
from tkinter import *
import final_back_iti
import sqlite3
#import matplotlib.pyplot as plt
import numpy as np
def openapp():
'''def admin():
conn=sqlite3.connect("polio.db")
cur=conn.cursor()
cur.execute("SELECT COUNT(Id), source FROM polio GROUP BY source")
row=cur.fetchall()
conn.close()
objects = []
target = []
[objects.append(i[0]) for i in row]
[target.append(i[1]) for i in row]
print(len(target))
plt.bar(np.arange(len(objects)),objects,align='center', alpha=0.5)
plt.xticks(np.arange(len(target)), target)
plt.show()
pass'''
def get_selected_row(event):
global selected_tuple
index=list1.curselection()[0]
selected_tuple=list1.get(index)
entry1.delete(0,END)
entry1.insert(END,selected_tuple[1])
entry2.delete(0,END)
entry2.insert(END,selected_tuple[2])
entry3.delete(0,END)
entry3.insert(END,selected_tuple[3])
entry4.delete(0,END)
entry4.insert(END,selected_tuple[4])
entry5.delete(0,END)
entry5.insert(END,selected_tuple[5])
entry6.delete(0,END)
entry6.insert(END,selected_tuple[6])
def view_command():
list1.delete(0,END)
for row in final_back_iti.view():
list1.insert(END,row)
def search_command():
list1.delete(0,END)
for row in final_back_iti.search(name_text.get(),source_text.get(),currentstatus_text.get(),roomtype_text.get(),noof_text.get(),amount_text.get()):
list1.insert(END,row)
def add_command():
final_back_iti.insert(name_text.get(),source_text.get(),currentstatus_text.get(),noof_text.get(),roomtype_text.get(),amount_text.get())
list1.delete(0,END)
list1.insert(END,(name_text.get(),source_text.get(),currentstatus_text.get(),noof_text.get(),roomtype_text.get(),amount_text.get()))
def delete_command():
final_back_iti.delete(selected_tuple[0])
def update_command():
final_back_iti.update(selected_tuple[0],name_text.get(),source_text.get(),currentstatus_text.get(),roomtype_text.get(),noof_text.get(),amount_text.get())
window=Tk()
window.title("Train Enquiry System")
window.configure(background="powder blue")
label1=Label(window,text="Welcome To Train Enquiry System",font=('none 13 bold'))
label1.grid(row=0,column=2)
label2=Label(window,text="Name",font=('none 13 bold'))
label2.grid(row=1,column=0)
label3=Label(window,text="Source",font=('none 13 bold'))
label3.grid(row=2,column=0)
label4=Label(window,text="currentstatus",font=('none 13 bold'))
label4.grid(row=3,column=0)
label5=Label(window,text="Destination",font=('none 13 bold'))
label5.grid(row=4,column=0)
label6=Label(window,text="ETA",font=('none 13 bold'))
label6.grid(row=5,column=0)
label7=Label(window,text="ETD",font=('none 13 bold'))
label7.grid(row=6,column=0)
name_text=StringVar()
entry1=Entry(window,textvariable=name_text)
entry1.grid(row=1,column=1)
source_text=StringVar()
entry2=Entry(window,textvariable=source_text)
entry2.grid(row=2,column=1)
currentstatus_text=StringVar()
entry3=Entry(window,textvariable=currentstatus_text)
entry3.grid(row=3,column=1)
noof_text=StringVar()
entry4=Entry(window,textvariable=noof_text)
entry4.grid(row=4,column=1)
roomtype_text=StringVar()
entry5=Entry(window,textvariable=roomtype_text)
entry5.grid(row=5,column=1)
amount_text=StringVar()
entry6=Entry(window,textvariable=amount_text)
entry6.grid(row=6,column=1)
list1=Listbox(window,height=20,width=59)
list1.grid(row=1,column=3, rowspan=6, columnspan=2)
scrl=Scrollbar(window)
scrl.grid(row=1,column=2, sticky='ns',rowspan=6)
list1.configure(yscrollcommand=scrl.set)
scrl.configure(command=list1.yview)
list1.bind('<<ListboxSelect>>',get_selected_row)
b1=Button(window,text="view all",width=12, command=view_command,font=('none 13 bold'),relief=RAISED)
b1.grid(row=7, column=0)
b2=Button(window,text="add entry",width=12,fg="green",command=add_command,font=('none 13 bold'),relief=RAISED)
b2.grid(row=8, column=0)
b3=Button(window,text="delete entry",width=12,fg="red",command=delete_command,font=('none 13 bold'),relief=RAISED)
b3.grid(row=10, column=0)
#b6=Button(window,text="Admin View",width=12,fg="Yellow",command=admin,font=('none 13 bold'),relief=RAISED)
#b6.grid(row=10, column=1)
b4=Button(window,text="search",width=12,command=search_command,font=('none 13 bold'),relief=RAISED)
b4.grid(row=7, column=1)
b5=Button(window,text="update",width=12,fg="blue",command=update_command,font=('none 13 bold'),relief=RAISED)
b5.grid(row=8, column=1)
window.mainloop()
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2
from tkinter import messagebox as ms
import sqlite3
# make database and users (if not exists already) table at programme start up
with sqlite3.connect('quit.db') as db:
c = db.cursor()
c.execute('CREATE TABLE IF NOT EXISTS user (username TEXT NOT NULL ,password TEX NOT NULL);')
db.commit()
db.close()
#main Class
class main:
def __init__(self,master):
# Window
self.master = master
# Some Usefull variables
self.username = StringVar()
self.password = StringVar()
self.n_username = StringVar()
self.n_password = StringVar()
#Create Widgets
self.widgets()
#Login Function
def login(self):
#Establish Connection
with sqlite3.connect('quit.db') as db:
c = db.cursor()
#Find user If there is any take proper action
find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
c.execute(find_user,[(self.username.get()),(self.password.get())])
result = c.fetchall()
if result:
root.destroy()
openapp()
else:
ms.showerror('Oops!','Username Not Found.')
def new_user(self):
#Establish Connection
with sqlite3.connect('quit.db') as db:
c = db.cursor()
#Find Existing username if any take proper action
find_user = ('SELECT * FROM user WHERE username = ?')
c.execute(find_user,[(self.username.get())])
if c.fetchall():
ms.showerror('Error!','Username Taken Try a Diffrent One.')
else:
ms.showinfo('Success!','Account Created!')
self.log()
#Create New Account
insert = 'INSERT INTO user(username,password) VALUES(?,?)'
c.execute(insert,[(self.n_username.get()),(self.n_password.get())])
db.commit()
#Frame Packing Methords
def log(self):
self.username.set('')
self.password.set('')
self.crf.pack_forget()
self.head['text'] = 'LOGIN'
self.logf.pack()
def cr(self):
self.n_username.set('')
self.n_password.set('')
self.logf.pack_forget()
self.head['text'] = 'Create Account'
self.crf.pack()
#Draw Widgets
def widgets(self):
self.head = Label(self.master,text = 'LOGIN',font = ('',35),pady = 10)
self.head.pack()
self.logf = Frame(self.master,padx =10,pady = 10)
Label(self.logf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=0,column=1)
Label(self.logf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
Button(self.logf,text = ' Login ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.login).grid()
Button(self.logf,text = ' Create Account ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.cr).grid(row=2,column=1)
self.logf.pack()
self.crf = Frame(self.master,padx =10,pady = 10)
Label(self.crf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
Entry(self.crf,textvariable = self.n_username,bd = 5,font = ('',15)).grid(row=0,column=1)
Label(self.crf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
Entry(self.crf,textvariable = self.n_password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
Button(self.crf,text = 'Create Account',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.new_user).grid()
Button(self.crf,text = 'Go to Login',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.log).grid(row=2,column=1)
#create window and application object
root = Tk()
#root.title("Login Form")
main(root)
root.mainloop()
######################################################################################################