-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final.py
1099 lines (979 loc) · 36.6 KB
/
Final.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from datetime import date
from tkinter import *
from tkinter import Button
import sqlite3
from tkinter.messagebox import *
from tkcalendar import *
import Modules.SignIn_Module.SignIn_page as SignIn
import Modules.DeleteAccount.AccountDelete as Acc_delete
con=sqlite3.Connection("My_database")
cur=con.cursor()
Check=SignIn.Login().mainloop()
def Transition_LoginToMain():
with open('Modules\\SignIn_Module\\SignIn_Check.txt', 'r') as file:
content = file.read()
value = bool(content)
#For debugging
# print(value)
if not value:
exit()
with open('Modules\\SignIn_Module\\SignIn_Check.txt', 'w') as file2:
file2.truncate(0)
Transition_LoginToMain()
root = Tk()
root.title("Python Bus Service")
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry("%dx%d" % (width, height))
def new_run():
f17 = Frame()
f17.place(
x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight()
)
my_label = Label(f17, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f17, text="Python Bus Service", font=("Arial", 25), bg="deep sky blue", fg="red"
).grid(row=1, column=0, columnspan=5)
Label(
f17, text="Add New Running Details", font=("Arial", 25), fg="light green"
).grid(row=2, column=0, columnspan=5, pady=20)
f18 = Frame(f17)
f18.grid(row=3, column=0, columnspan=15, pady=20)
Label(f18, text="Bus Id ", font=("Arial", 15), fg="light green").grid(
row=0, column=0, padx=20
)
e23 = Entry(f18)
e23.grid(row=0, column=1)
Label(
f18, text="Running Date (DD-MM-YY)", font=("Arial", 15), fg="light green"
).grid(row=0, column=2, padx=20)
e24 = Entry(f18)
e24.grid(row=0, column=3)
Label(f18, text="Seat Available", font=("Arial", 15), fg="light green").grid(
row=0, column=4, padx=10 + 10
)
e25 = Entry(f18)
e25.grid(row=0, column=5)
def add_run():
cur.execute(
'select * from runs where bus_id='
+ e23.get()
+ " and journey_date="
+ e24.get()
)
already = cur.fetchall()
if len(already):
showerror("Error", "Route details already exist")
else:
cur.execute(
'insert into runs(bus_id,journey_date,seat_available) values(?,?,?)',
(int(e23.get()), e24.get(), e25.get()),
)
con.commit()
cur.execute(
'select * from runs where bus_id='
+ e23.get()
+ ' and journey_date="'
+ e24.get()
+ '"'
)
row = cur.fetchall()
row = row[0]
con.commit()
showinfo("Successful", "Data added successfully\n" + str(row))
def delete_run():
cur.execute(
'DELETE FROM runs WHERE bus_id='
+ e23.get()
+ ' AND journey_date="'
+ e24.get()
+ '"'
)
con.commit()
showinfo("Deleted", "Bus running details deleted successfully!!")
button20 = Button(
f18, text="Add Run", font=("Arial", 15), bg="light green", command=add_run
).grid(row=0, column=6, padx=20, pady=20)
button21 = Button(
f18,
text="Delete",
font=("Arial", 15),
fg="red",
bg="light green",
command=delete_run,
).grid(row=0, column=7, padx=20, pady=20)
button22 = Button(f17, image=home_img, anchor=CENTER, command=tab2).grid(
row=4, column=0, columnspan=5
)
def change_theme():
current_bg = f17.cget("bg") # Get the current background color
if current_bg == "white":
f17.configure(bg="gray70")
f18.configure(bg="gray70")
else:
f17.configure(bg="white")
f18.configure(bg="white")
buttonTheme = Button(f17, text="Theme",command=change_theme, width=35).grid(
row=6, column=0, columnspan=5
)
def new_route():
f15 = Frame()
f15.place(
x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight()
)
my_label = Label(f15, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f15, text="Python Bus Service", font=("Arial", 25), bg="deep sky blue", fg="red"
).grid(row=1, column=0, columnspan=5)
Label(f15, text="Add Bus Route Details", font=("Arial", 25), fg="light green").grid(
row=2, column=0, columnspan=5, pady=20
)
f16 = Frame(f15)
f16.grid(row=3, column=0, columnspan=15, pady=20)
Label(f16, text="Route Id ", font=("Arial", 15), fg="light green").grid(
row=0, column=0, padx=20
)
e20 = Entry(f16)
e20.grid(row=0, column=1)
Label(f16, text="Station Name ", font=("Arial", 15), fg="light green").grid(
row=0, column=2, padx=20
)
e21 = Entry(f16)
e21.grid(row=0, column=3)
Label(f16, text="Station ID ", font=("Arial", 15), fg="light green").grid(
row=0, column=4, padx=10 + 10
)
e22 = Entry(f16)
e22.grid(row=0, column=5)
def add_route():
cur.execute(
'select * from route where route_id='
+ e20.get()
+ ' and station="'
+ e21.get()
+ '" and s_id='
+ e22.get()
)
already = cur.fetchall()
if len(already):
showerror("Error", "Route details already exist")
else:
cur.execute(
'insert into route (route_id ,station ,s_id) values (?,?,?)',
(int(e20.get()), e21.get(), int(e22.get())),
)
cur.execute(
'select * from route where route_id='
+ e20.get()
+ " and s_id="
+ e22.get()
)
row = cur.fetchall()
row = row[0]
con.commit()
showinfo("Successful", "Data added successfully\n" + str(row))
def delete_route():
cur.execute(
'DELETE FROM route WHERE route_id=? and station=? and s_id=?',
(int(e20.get()), e21.get(), int(e22.get())),
)
con.commit()
showinfo("Deleted", "Route Deleted Successfully")
button20 = Button(
f16, text="Add Route", font=("Arial", 15), bg="light green", command=add_route
).grid(row=0, column=6, padx=20, pady=20)
button21 = Button(
f16,
text="Delete",
font=("Arial", 15),
fg="red",
bg="light green",
command=delete_route,
).grid(row=0, column=7, padx=20, pady=20)
button22 = Button(f15, image=home_img, anchor=CENTER, command=tab2).grid(
row=4, column=0, columnspan=5
)
def change_theme():
current_bg = f15.cget("bg") # Get the current background color
if current_bg == "white":
f15.configure(bg="gray70")
f16.configure(bg="gray70")
else:
f15.configure(bg="white")
f16.configure(bg="white")
buttonTheme = Button(f15, text="Theme",command=change_theme, width=35).grid(
row=6, column=0, columnspan=5
)
def new_bus():
f13 = Frame()
f13.place(
x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight()
)
my_label = Label(f13, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f13, text="Python Bus Service", font=("Arial", 25), bg="deep sky blue", fg="red"
).grid(row=1, column=0, columnspan=5)
Label(f13, text="Add Bus Details", font=("Arial", 25), fg="light green").grid(
row=2, column=0, columnspan=5, pady=20
)
f14 = Frame(f13)
f14.grid(row=3, column=0, columnspan=15, pady=20)
Label(f14, text="Bus Id ", font=("Arial", 15), fg="light green").grid(
row=0, column=0, padx=20
)
e14 = Entry(f14)
e14.grid(row=0, column=1)
Label(f14, text="Bus Type ", font=("Arial", 15), fg="light green").grid(
row=0, column=2, padx=20
)
menu1 = StringVar()
menu1.set("CHOOSE")
drop2 = OptionMenu(
f14,
menu1,
"AC 2x2",
"AC 3x2",
"Non-AC 2x2",
"Non-AC 3x2",
"AC Sleeper 2x2",
"Non-AC Sleeper 2x2",
).grid(row=0, column=3)
Label(f14, text="Capacity ", font=("Arial", 15), fg="light green").grid(
row=0, column=4, padx=20
)
e16 = Entry(f14)
e16.grid(row=0, column=5)
Label(f14, text="Fare Rs ", font=("Arial", 15), fg="light green").grid(
row=0, column=6, padx=15
)
e17 = Entry(f14)
e17.grid(row=0, column=7)
Label(f14, text="Operator ID", font=("Arial", 15), fg="light green").grid(
row=0, column=8, padx=19
)
e18 = Entry(f14)
e18.grid(row=0, column=9)
Label(f14, text="Route ID", font=("Arial", 15), fg="light green").grid(
row=0, column=10, padx=19
)
e19 = Entry(f14)
e19.grid(row=0, column=11)
def add_bus():
cur.execute(
'select * from bus where bus_id=' + e14.get() + ' and route_id=' + e19.get()
)
already = cur.fetchall()
if len(already):
showerror("Error", "Bus Id already exist")
else:
cur.execute(
'insert into bus (bus_id,type,capacity,fare,route_id,op_id) values (?,?,?,?,?,?)',
(
int(e14.get()),
menu1.get(),
int(e16.get()),
int(e17.get()),
int(e19.get()),
int(e18.get()),
),
)
cur.execute(
'select * from bus where bus_id='
+ e14.get()
+ ' and route_id='
+ e19.get()
)
row = cur.fetchall()
row = row[0]
con.commit()
showinfo("Successful", "Data added successfully\n" + str(row))
def delete_bus():
cur.execute('DELETE FROM bus WHERE bus_id=' + e14.get())
con.commit()
showinfo("Deleted", "Bus Details Deleted Successfully")
button17 = Button(
f14,
text="Add Bus",
font=("Arial", 15),
bg="light green",
anchor=CENTER,
command=add_bus,
).grid(row=1, column=4, padx=20, pady=20)
button18 = Button(
f14,
text="Delete",
font=("Arial", 15),
bg="light green",
anchor=CENTER,
command=delete_bus,
).grid(row=1, column=6, padx=20, pady=20)
button19 = Button(f13, image=home_img, anchor=CENTER, command=tab2).grid(
row=4, column=0, columnspan=5
)
def change_theme():
current_bg = f13.cget("bg") # Get the current background color
if current_bg == "white":
f13.configure(bg="gray70")
f14.configure(bg="gray70")
else:
f13.configure(bg="white")
f14.configure(bg="white")
buttonTheme = Button(f13, text="Theme",command=change_theme, width=35).grid(
row=6, column=0, columnspan=5
)
def new_operator():
f11 = Frame()
f11.place(
x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight()
)
my_label = Label(f11, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f11, text="Python Bus Service", font=("Arial", 25), bg="deep sky blue", fg="red"
).grid(row=1, column=0, columnspan=5)
Label(f11, text="Add Bus Operator Details", font=("Arial", 25), fg="green").grid(
row=2, column=0, columnspan=5
)
f12 = Frame(f11)
f12.grid(row=3, column=0, columnspan=15, pady=20)
Label(f12, text="Operator Id ", font=("Arial", 12), fg="green").grid(
row=0, column=0, padx=20
)
e9 = Entry(f12)
e9.grid(row=0, column=1)
Label(f12, text="Name ", font=("Arial", 12), fg="green").grid(
row=0, column=2, padx=20
)
e10 = Entry(f12)
e10.grid(row=0, column=3)
Label(f12, text="Address ", font=("Arial", 12), fg="green").grid(
row=0, column=4, padx=20
)
e11 = Entry(f12)
e11.grid(row=0, column=5)
Label(f12, text="Phone ", font=("Arial", 12), fg="green").grid(
row=0, column=6, padx=10 + 10
)
e12 = Entry(f12)
e12.grid(row=0, column=7)
Label(f12, text="E-mail", font=("Arial", 12), fg="green").grid(
row=0, column=8, padx=19 + 1
)
e13 = Entry(f12)
e13.grid(row=0, column=9)
def add_op():
cur.execute('select * from operator where op_id=' + e9.get())
already = cur.fetchall()
if len(already):
showerror("Error", "Operator Id already exist")
else:
cur.execute(
"insert into operator (op_id ,name ,address ,phone , email) values (?,?,?,?,?)",
(int(e9.get()), e10.get(), e11.get(), int(e12.get()), e13.get()),
)
cur.execute('select * from operator where op_id=' + e9.get())
row = cur.fetchall()
row = row[0]
con.commit()
showinfo("Successful", "Data added successfully\n" + str(row))
def delete_op():
cur.execute(
"DELETE FROM operator WHERE op_id="
+ e9.get()
+ ' and name="'
+ e10.get()
+ '" and address="'
+ e11.get()
+ '" and phone='
+ e12.get()
+ ' and email="'
+ e13.get()
+ '"'
)
con.commit()
showinfo("Deleted", "Operator Details Deleted Successfully")
button15 = Button(
f12, text="Add", font=("Arial", 15), bg="light green", command=add_op
).grid(row=1, column=4, padx=20)
button16 = Button(
f12, text="Delete", font=("Arial", 15), bg="light green", command=delete_op
).grid(row=1, column=6, padx=20)
button14 = Button(f11, image=home_img, anchor=CENTER, command=tab2).grid(
row=4, column=0, columnspan=5
)
def change_theme():
current_bg = f11.cget("bg") # Get the current background color
if current_bg == "white":
f11.configure(bg="gray70")
f12.configure(bg="gray70")
else:
f11.configure(bg="white")
f12.configure(bg="white")
buttonTheme = Button(f11, text="Theme",command=change_theme, width=35).grid(
row=6, column=0, columnspan=5
)
def ticketShow(row):
f4 = Frame()
f4.place(x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight())
my_label = Label(f4, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f4, text="Python Bus Service", font=("Arial", 25), bg="deep sky blue", fg="red"
).grid(row=1, column=0, columnspan=5)
Label(
f4, text="BUS TICKET", font=("Arial", 20), bg="light green", fg="green4", bd=5
).grid(row=3, column=0, columnspan=5, pady=20)
final = LabelFrame(f4)
final.grid(row=5, column=0, columnspan=5)
Label(final, text="Passenger: " + row[1]).grid(row=6, column=0)
Label(final, text="No of seats: " + str(row[6])).grid(row=7, column=0)
Label(final, text="Age: " + str(row[3])).grid(row=8, column=0)
Label(final, text="Travel on: " + row[5]).grid(row=9, column=0)
Label(final, text="Gender: " + row[2] + " ").grid(
row=6, column=7, columnspan=3
)
Label(final, text="Phone: " + str(row[0]) + " ").grid(
row=7, column=7, columnspan=3
)
Label(final, text="Fare Rs: " + str(row[7]) + " ").grid(
row=8, column=7, columnspan=3
)
Label(final, text="Bus Id: " + str(row[4]) + " ").grid(
row=9, column=7, columnspan=3
)
Label(final, text="Boarding Point: " + row[8] + " ").grid(
row=10, column=7, columnspan=3
)
Label(
final,
text="Total Rs. "
+ str(row[7] * row[6])
+ " you have to pay at the time of boarding: ",
).grid(row=11, column=0, columnspan=3)
showinfo("Successful", "Ticket Book Sucessfully")
button2 = Button(f4, image=home_img, anchor=CENTER, command=tab2).grid(
row=16, column=2, pady=50
)
def change_theme():
current_bg = f4.cget("bg") # Get the current background color
if current_bg == "white":
f4.configure(bg="gray70")
final.configure(bg="gray70")
else:
f4.configure(bg="white")
final.configure(bg="white")
buttonTheme = Button(f4, text="Theme",command=change_theme, width=35).grid(
row=6, column=0, columnspan=5
)
def seat_book():
f4 = Frame()
f4.place(x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight())
my_label = Label(f4, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
label1=Label(
f4, text="Python Bus Service", font=("Arial", 25), bg="deep sky blue", fg="red"
).grid(row=1, column=0, columnspan=5)
label2=Label(
f4,
text="Enter Journey Details",
font=("Arial", 20),
bg="light green",
fg="green4",
bd=5,
).grid(row=3, column=0, columnspan=5, pady=20)
f5 = Frame(f4, pady=20)
f5.grid(row=4, column=0, columnspan=5)
label3=Label(f5, text="TO ", font=("Arial", 10)).grid(row=0, column=0, sticky=E)
e1 = Entry(f5)
e1.grid(row=0, column=1)
label4=Label(f5, text="FROM ", font=("Arial", 10)).grid(row=0, column=2)
e2 = Entry(f5)
e2.grid(row=0,column=3)
label5=Label(f5,text = "JOURNEY DATE (MM-DD-YYYY) ", font=("Arial",10)).grid(row=0,column=4)
cal=DateEntry(f5,selectmode='day', date_pattern = "MM-DD-YYYY")
cal.grid(row=0,column=5,padx=15)
'''e3 = Entry(f5)
e3.grid(row=0,column=5)'''
def proceed_to(f5, busch, fare):
if type(busch) != int:
showinfo("Invalid Choice", "Please choose a bus!")
else:
f6 = Frame(f5)
f6.grid(row=6, column=0, columnspan=10, pady=20)
Label(
f6,
text="Fill Passenger Details To Book The Bus Ticket",
font=("Arial", 25),
bg="deep sky blue",
fg="red",
).grid(row=0, column=0, columnspan=15)
Label(f6, text="Name", font=("Arial", 15)).grid(
row=1, column=0, padx=20, pady=20
)
e4 = Entry(f6)
e4.grid(row=1, column=1)
Label(f6, text="Gender", font=("Arial", 15)).grid(
row=1, column=2, padx=20, pady=20
)
menu = StringVar()
menu.set("CHOOSE")
drop1 = OptionMenu(f6, menu, "MALE", "FEMALE", "TRANS").grid(
row=1, column=3
)
Label(f6, text="No. of seats.", font=("Arial", 15)).grid(
row=1, column=4, padx=20, pady=20
)
e5 = Entry(f6)
e5.grid(row=1, column=5)
Label(f6, text="Mobile No", font=("Arial", 15)).grid(
row=1, column=6, padx=20, pady=20
)
e6 = StringVar()
Entry(f6, textvariable=e6).grid(row=1, column=7)
Label(f6, text="Age", font=("Arial", 15)).grid(
row=1, column=8, padx=20, pady=20
)
e7 = Entry(f6)
e7.grid(row=1, column=9)
def booked(fare):
if e6.get()=="" or e4.get()=="" or e7.get()=="" or cal.get()=="" or e5.get()=="" or e2.get()=="" or e1.get()=="":
showerror("Invalid Data","Please fill all the data!")
else:
insertRow = (int(e6.get()),e4.get(),menu.get(),int(e7.get()),busch,cal.get(),int(e5.get()),fare,e2.get(),e1.get())
fare*=insertRow[6]
cur.execute('select seat_available from runs where bus_id='+str(busch)+' and journey_date="'+cal.get()+'"')
seats_avail=cur.fetchall()
seats_avl=int(seats_avail[0][0])
if int(e5.get())<seats_avl:
resp = askyesno("Book","Total fare = "+str(fare)+"\nProceed to book?")
if resp:
cur.execute('insert into Booking (Mobile ,Name ,sex ,age ,Bus_id , journey_date ,Ticket, Fare ,FromSt ,Tost ) values (?,?,?,?,?,?,?,?,?,?)',insertRow)
cur.execute('update runs set seat_available='+str(seats_avl-int(e5.get()))+' where bus_id='+str(busch)+' and journey_date="'+cal.get()+'"')
con.commit()
ticketShow(insertRow)
else:
showerror(
"Limited Seats", "Insufficient seats avilable in the bus!"
)
def seat_matrix():
import tkinter as tk
from tkinter import messagebox
def submit(root):
selected_seats = []
for seat_var in seat_vars:
if seat_var.get() != "":
selected_seats.append(seat_var.get())
#print("Selected seats:", selected_seats)
root.destroy() # Close the window after submitting
messagebox.showinfo("Tickets Selected","Tickets Selected")
root = tk.Tk()
root.title("Seat Matrix")
bus_frame = tk.Frame(root)
root.geometry("400x500")
bus_frame.pack()
seat_vars = []
seat_checkboxes = []
for row in range(1, 11):
seat_row = tk.Frame(bus_frame)
seat_row.grid(row=row, column=1)
row_label = tk.Label(seat_row, text=f"Row {row}", font=("Arial", 10, "bold"))
row_label.pack(side=tk.TOP)
for col in range(1, 5):
seat_var = tk.StringVar()
seat_checkbox = tk.Checkbutton(seat_row, text=f"Seat {col}", variable=seat_var, onvalue=f"Seat {col}", offvalue="")
seat_checkbox.pack(side=tk.LEFT)
seat_vars.append(seat_var)
seat_checkboxes.append(seat_checkbox)
if col == 2:
empty_label = tk.Label(seat_row, text=" ", width=5)
empty_label.pack(side=tk.LEFT)
seat_row.grid(row=row, column=1)
submit_button = tk.Button(root, text="Submit", command=lambda: submit(root))
submit_button.pack(pady=10)
root.mainloop()
#Button For seat matrix
button8 = Button(
f6,
text="Seat Matrix",
font=("Arial", 15),
activebackground="light green",
bg="SpringGreen3",
command=seat_matrix,
).grid(row=1, column=10, padx=20, pady=20)
button9 = Button(
f6,
text="Book Seat",
font=("Arial", 15),
activebackground="light green",
bg="SpringGreen3",
command=lambda: booked(fare),
).grid(row=1, column=11, padx=20, pady=20)
def show_bus(f5):
if e1.get()=="" or e2.get()=="" or cal.get()=="":
showinfo("Invalid Inputs","Please enter all the details!")
else:
data=cur.execute('select b.bus_id,o.name,b.type,t.seat_available,b.fare from route r,route s,runs t,bus b,operator o where o.op_id=b.op_id and r.route_id=s.route_id and t.bus_id=b.bus_id and b.route_id=r.route_id and t.journey_date= "'+str(cal.get())+'" and r.station="'+str(e1.get())+'" and s.station="'+str(e2.get())+'" and r.s_id>s.s_id')
f6=Frame(f5)
f6.grid(row = 5, column = 0, columnspan = 10,pady = 20)
Label(f6,text = "Select BUS ", font=("Arial",15),fg='light green').grid(row=0,column=0,padx = 20)
Label(f6,text = "Operator ", font=("Arial",15),fg='light green').grid(row=0,column=1,padx=20)
Label(f6,text = "Bus Type ", font=("Arial",15),fg='light green').grid(row=0,column=2,padx= 20)
Label(f6,text = "Availability ", font=("Arial",15),fg='light green').grid(row=0,column=3,padx = 10+10)
Label(f6,text = "Fare ", font=("Arial",15),fg='light green').grid(row=0,column=4, padx = 19+1)
i,busch=1,IntVar()
for row in data:
rb = Radiobutton(f6, text="Bus" + str(i), variable=busch, value=row[0])
rb.grid(row=i, column=0)
Label(f6, text=str(row[1]), fg="green").grid(row=i, column=1)
Label(f6, text=str(row[2]), fg="green").grid(row=i, column=2)
Label(f6, text=str(row[3]), fg="green").grid(row=i, column=3)
Label(f6, text=str(row[4]), fg="green").grid(row=i, column=4)
i += 1
if i == 1:
showinfo("Not Found", "No bus found for given details!")
button7 = Button(
f6,
text="Proceed to Book",
font=("Arial", 15),
activebackground="light green",
bg="SpringGreen3",
command=lambda: proceed_to(f5, busch.get(), row[4]),
).grid(row=1, column=5, padx=20, pady=20)
button5 = Button(
f5,
text="Show Bus",
font=("Arial", 15),
activebackground="light green",
bg="SpringGreen3",
command=lambda: show_bus(f5),
).grid(row=0, column=6, padx=20)
button6 = Button(f5, image=home_img, command=tab2).grid(row=0, column=7, padx=20)
def change_theme():
current_bg = f5.cget("bg") # Get the current background color
if current_bg == "white":
f5.configure(bg="gray70")
f4.configure(bg="gray70")
else:
f5.configure(bg="white")
f4.configure(bg="white")
buttonTheme = Button(f4, text="Theme",command=change_theme, width=35).grid(
row=6, column=0, columnspan=5
)
text = ""
def check_booked_seat(f2):
f7 = Frame(f2)
f7.place(x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight())
my_label = Label(f7, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f7,
text="Python Bus Service",
font=("Arial", 25),
bg="deep sky blue",
fg="red",
anchor=CENTER,
).grid(row=1, column=0, columnspan=5)
Label(
f7,
text="Check Your Booking",
font=("Arial", 25),
bg="light green",
fg="forest green",
).grid(row=2, column=0, columnspan=10, pady=20)
f8 = Frame(f7)
f8.grid(row=3, column=0, pady=20, columnspan=5)
Label(f8, text="Enter Your Mobile No.", font=("Arial", 15)).grid(row=0, column=0)
e8 = Entry(f8)
e8.grid(row=0, column=1, padx=20)
def checkHistory():
MobNo = e8.get()
if len(e8.get()) != 10:
showerror("Value Missing", "Enter correct Mobile Number!!")
elif e8.get() == "":
showerror("Error", "Value missing!!!")
else:
cur.execute(
"select name,sex,ticket,mobile,age,fare,ref_id,bus_id,fromst,tost,journey_date from booking where Mobile="
+ str(e8.get())
+ " order by ref_id desc limit 1"
)
con.commit()
details = cur.fetchall()
i = 5
for row in details:
box = Label(
f8,
text="Name: "
+ row[0]
+ "\nGender: "
+ row[1]
+ "\nNo. of seats: "
+ str(row[2])
+ "\nPhone: "
+ str(row[3])
+ "\nAge: "
+ str(row[4])
+ "\nFare Rs: "
+ str(row[5])
+ "\nBooking ref: "
+ str(row[6])
+ "\nBus Id: "
+ str(row[7])
+ "\nBoarding point: "
+ row[8]
+ "\nDestination: "
+ row[9]
+ "\nTravel On: "
+ row[10]
+ "\n\n *Total amount Rs "
+ str(row[5] * row[2])
+ " to be paid at time of boarding the bus",
font="bold",
relief="groove",
)
box.grid(row=i, column=0, columnspan=3)
#Adding Ticket data into pdf
label_text = box.cget("text")
global text
text = label_text
i += 1
#Download Ticket
button10 = Button(f7, text="Download Ticket", anchor=CENTER, command=download_ticket).grid(
row=4, column=0, columnspan=5)
temp_label = Label(f7, text="", anchor=CENTER).grid(
row=5, column=0, columnspan=5)
if i == 5:
showerror("Test", "No tickets found!!")
button8 = Button(
f8, text="Check Booking", font=("Arial", 15), command=checkHistory
).grid(row=0, column=2, padx=20)
button9 = Button(f7, image=home_img, anchor=CENTER, command=tab2).grid(
row=6, column=0, columnspan=5
)
button9 = Button(f7, image=home_img, anchor=CENTER, command=tab2).grid(
row=6, column=0, columnspan=5
)
def change_theme():
current_bg = f7.cget("bg") # Get the current background color
if current_bg == "white":
f7.configure(bg="gray70")
f8.configure(bg="gray70")
else:
f7.configure(bg="white")
f8.configure(bg="white")
buttonTheme = Button(f7, text="Theme",command=change_theme, width=35).grid(
row=7, column=0, columnspan=5
)
def add_bus():
f9 = Frame()
f9.place(x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight())
my_label = Label(f9, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f9,
text="Python Bus Service",
font=("Arial", 25),
bg="deep sky blue",
fg="red",
anchor=CENTER,
).grid(row=1, column=0, columnspan=5)
Label(
f9,
text="Add New Details to Database",
font=("Arial", 25),
bd=5,
fg="light green",
bg="green",
).grid(row=2, column=0, columnspan=10, pady=20)
f10 = Frame(f9)
f10.grid(row=3, column=0, pady=20, columnspan=10)
button10 = Button(
f10,
text="New Operator",
font=("Arial", 15),
bg="light green",
command=new_operator,
).grid(row=0, column=0, padx=20)
button11 = Button(
f10,
text="New Bus",
font=("Arial", 15),
bg="orange",
anchor=CENTER,
command=new_bus,
).grid(row=0, column=1, padx=20)
button12 = Button(
f10,
text="New Route",
font=("Arial", 15),
bg="SlateBlue1",
anchor=CENTER,
command=new_route,
).grid(row=0, column=2, padx=20)
button13 = Button(
f10,
text="New Run",
font=("Arial", 15),
bg="sienna3",
anchor=CENTER,
command=new_run,
).grid(row=0, column=3, padx=20)
button23 = Button(f9, image=home_img, anchor=CENTER, command=tab2).grid(
row=4, column=0, columnspan=5
)
#bg varibale 0 = white and bg variable 1 = dark mode
def change_theme():
current_bg = f9.cget("bg") # Get the current background color
if current_bg == "white":
f9.configure(bg="gray70")
f10.configure(bg="gray70")
else:
f9.configure(bg="white")
f10.configure(bg="white")
buttonTheme = Button(f9, text="Theme",command=change_theme, width=35).grid(
row=5, column=0, columnspan=5
)
#Second tkinter GUI page
def tab2():
f2 = Frame()
f2.place(x=0, y=0, width=root.winfo_screenwidth(), height=root.winfo_screenheight())
my_label = Label(f2, image=my_img, anchor=CENTER, width=width).grid(
row=0, column=0, columnspan=5
)
Label(
f2,
text="Python Bus Service",
font=("Arial", 25),
bg="deep sky blue",
fg="red",
anchor=CENTER,
).grid(row=1, column=0, columnspan=5)
f3 = Frame(f2, pady=25)
f3.grid(row=2, column=0, columnspan=5)
button2 = Button(
f3,
text="SEAT BOOKING",
font=("Arial", 15),
bg="light green",
padx=10,
pady=10,
command=seat_book,
).grid(row=1, column=0)
# Label(f3, text=" ").grid(row=0, column=1)
button2 = Button(
f3,
text="CHECK BOOKED SEAT",
font=("Arial", 15),
bg="light green",
padx=10,
pady=10,
command=lambda: check_booked_seat(f2),
).grid(row=1, column=2)
# Label(f3, text=" ").grid(row=0, column=3)
button3 = Button(
f3,
text="ADD BUS DETAILS",
font=("Arial", 15),
bg="light green",
padx=10,
pady=10,
command=add_bus,
).grid(row=1, column=4)
adminlabel=Label(f3, text="For Admins Only", fg="red")
adminlabel.grid(row=2, column=4)
button4 = Button(f2, image=home_img, anchor=CENTER, command=tab2).grid(
row=3, column=0, columnspan=5
)
#bg varibale 0 = white and bg variable 1 = dark mode
def change_theme():
current_bg = f2.cget("bg") # Get the current background color