Bank Management Sytem Using Python - Complete code

Bank Management Sytem Using Python – Complete code

Introduction

If you looking for an python project for your resume to showcase Your skiils in python . You can defentiley try This Bank management system using python. this project has everything include in it . This complete project built on python tkinter liababry with sql lite database.

Feature Of Bank Management system Using Python

  1. User Authentication
Feature Of Bank Management system Using Python
  • Login and registration system
  • Password encryption using SHA-256
  • User profile management

2. Account Management

Feature Of Bank Management system Using Python
  • Create different account types (Savings, Checking, Fixed Deposit, Loan)
  • View account details and transactions
  • Close accounts

3. Transactions

Feature Of Bank Management system Using Python
  • Deposits and withdrawals
  • Account-to-account transfers
  • Transaction history with detailed views

4. Dashboard

Feature Of Bank Management system Using Python
  • Overview of accounts and balances
  • Recent transaction activity
  • Quick action buttons

5. UI Features

  • Modern design with custom colors
  • Animations for transitions
  • Icons for navigation
  • Responsive layout

5. Database

  • SQLite database for data persistence
  • Tables for users, accounts, and transactions

Requirments Of Bank Management system Using Python

Programming languagePython
LiabaryTkinter
DatabaseSQLite
IDE / Code EditorSublime text

Complete Code

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
import sqlite3
import os
import base64
import time
import random
import hashlib
import datetime
from math import sin
from PIL import Image, ImageTk, ImageDraw
import io
import threading
 
class BankManagementSystem:
    def __init__(self, root):
        self.root = root
        self.root.title("Modern Bank Management System")
        self.root.geometry("1100x650")
        self.root.resizable(True, True)
        self.root.configure(bg="#f5f5f5")
         
        # Initialize database
        self.create_database()
         
        # Load and set icon
        self.load_icons()
         
        # Colors
        self.primary_color = "#1a73e8"
        self.secondary_color = "#f5f5f5"
        self.accent_color = "#4285f4"
        self.text_color = "#202124"
        self.error_color = "#ea4335"
        self.success_color = "#34a853"
         
        # Variables
        self.current_user = None
        self.current_frame = None
        self.animation_running = False
         
        # Start with login screen
        self.show_login()
     
    def create_database(self):
        """Create database and tables if they don't exist"""
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        # Create Users table
        cursor.execute('''
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            username TEXT UNIQUE NOT NULL,
            password TEXT NOT NULL,
            full_name TEXT NOT NULL,
            email TEXT UNIQUE NOT NULL,
            phone TEXT,
            address TEXT,
            registration_date TEXT,
            profile_pic BLOB
        )
        ''')
         
        # Create Accounts table
        cursor.execute('''
        CREATE TABLE IF NOT EXISTS accounts (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            user_id INTEGER,
            account_number TEXT UNIQUE NOT NULL,
            account_type TEXT NOT NULL,
            balance REAL DEFAULT 0.0,
            opening_date TEXT,
            status TEXT DEFAULT 'active',
            FOREIGN KEY (user_id) REFERENCES users(id)
        )
        ''')
         
        # Create Transactions table
        cursor.execute('''
        CREATE TABLE IF NOT EXISTS transactions (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            account_id INTEGER,
            transaction_type TEXT NOT NULL,
            amount REAL NOT NULL,
            description TEXT,
            transaction_date TEXT,
            reference_number TEXT,
            status TEXT DEFAULT 'completed',
            FOREIGN KEY (account_id) REFERENCES accounts(id)
        )
        ''')
         
        conn.commit()
        conn.close()
     
    def load_icons(self):
        """Load and prepare icons"""
        # Create a dictionary to store icons
        self.icons = {}
         
        # Function to generate a simple icon as base64 string
        def create_icon(color, shape="circle", size=64):
            img = Image.new('RGBA', (size, size), (0, 0, 0, 0))
            draw = ImageDraw.Draw(img)
             
            if shape == "circle":
                draw.ellipse((4, 4, size-4, size-4), fill=color)
            elif shape == "square":
                draw.rectangle((4, 4, size-4, size-4), fill=color)
            elif shape == "home":
                # Simple house shape
                draw.polygon([(size//2, 4), (size-4, size//2), (size-4, size-4), (4, size-4), (4, size//2)], fill=color)
            elif shape == "user":
                # User icon
                draw.ellipse((size//4, 4, 3*size//4, size//2), fill=color)  # Head
                draw.ellipse((size//8, size//2, 7*size//8, size-4), fill=color)  # Body
                 
            buffer = io.BytesIO()
            img.save(buffer, format="PNG")
            return base64.b64encode(buffer.getvalue())
         
        # Generate and store icons
        self.icons["home"] = create_icon("#1a73e8", "home")
        self.icons["user"] = create_icon("#4285f4", "user")
        self.icons["account"] = create_icon("#34a853", "circle")
        self.icons["transaction"] = create_icon("#fbbc04", "square")
        self.icons["logout"] = create_icon("#ea4335", "circle")
         
        # Create PhotoImage objects for icons
        self.icon_images = {}
        for name, data in self.icons.items():
            image_data = base64.b64decode(data)
            image = Image.open(io.BytesIO(image_data))
            self.icon_images[name] = ImageTk.PhotoImage(image)
     
    def apply_style(self):
        """Apply custom styles to widgets"""
        style = ttk.Style()
        style.theme_use('clam')
         
        # Configure styles for different widget types
        style.configure('TFrame', background=self.secondary_color)
        style.configure('TLabel', background=self.secondary_color, foreground=self.text_color, font=('Helvetica', 10))
        style.configure('TEntry', fieldbackground='white', font=('Helvetica', 10))
        style.configure('TButton',
                        background=self.primary_color,
                        foreground='white',
                        font=('Helvetica', 10, 'bold'),
                        borderwidth=0,
                        focusthickness=3,
                        focuscolor=self.accent_color)
        style.map('TButton',
                 background=[('active', self.accent_color), ('disabled', '#cccccc')],
                 foreground=[('disabled', '#666666')])
     
    def create_custom_button(self, parent, text, command, icon=None, **kwargs):
        """Create a custom styled button with optional icon"""
        frame = ttk.Frame(parent, style='Custom.TFrame')
         
        if icon:
            icon_label = ttk.Label(frame, image=self.icon_images.get(icon))
            icon_label.pack(side=tk.LEFT, padx=(5, 0))
         
        button = ttk.Button(frame, text=text, command=command, **kwargs)
        button.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(5 if icon else 0, 5), pady=5)
         
        return frame
     
    def animate_frame(self, frame, direction="right"):
        """Animate frame transition"""
        if self.animation_running:
            return
             
        self.animation_running = True
         
        # Hide all frames
        for widget in self.root.winfo_children():
            if isinstance(widget, ttk.Frame) and widget != frame:
                widget.place_forget()
         
        # Set initial position
        width = self.root.winfo_width()
        if direction == "right":
            frame.place(x=width, y=0, width=width, height=self.root.winfo_height())
            target_x = 0
            start_x = width
        else:  # left
            frame.place(x=-width, y=0, width=width, height=self.root.winfo_height())
            target_x = 0
            start_x = -width
         
        # Animation function
        def animate_step(current_x, step=0):
            new_x = int(start_x + (target_x - start_x) * sin(step/20))
            frame.place(x=new_x, y=0, width=width, height=self.root.winfo_height())
            step += 1
             
            if step <= 20:
                self.root.after(10, lambda: animate_step(new_x, step))
            else:
                frame.place(x=target_x, y=0, relwidth=1, relheight=1)
                self.animation_running = False
                self.current_frame = frame
         
        animate_step(start_x)
     
    def show_login(self):
        """Display the login frame"""
        login_frame = ttk.Frame(self.root, style='TFrame')
         
        # Logo at the top
        logo_frame = ttk.Frame(login_frame, style='TFrame')
        logo_frame.pack(pady=30)
         
        # Create a circular logo
        canvas = tk.Canvas(logo_frame, width=100, height=100, bg=self.secondary_color, highlightthickness=0)
        canvas.create_oval(10, 10, 90, 90, fill=self.primary_color, outline="")
        canvas.create_text(50, 50, text="BMS", fill="white", font=("Helvetica", 24, "bold"))
        canvas.pack()
         
        # Title
        title_label = ttk.Label(login_frame, text="Bank Management System", font=("Helvetica", 24, "bold"), style='TLabel')
        title_label.pack(pady=10)
         
        # Login form
        form_frame = ttk.Frame(login_frame, style='TFrame')
        form_frame.pack(pady=20, padx=50, fill=tk.X)
         
        username_label = ttk.Label(form_frame, text="Username:", style='TLabel')
        username_label.grid(row=0, column=0, sticky=tk.W, pady=5)
         
        username_entry = ttk.Entry(form_frame, width=30)
        username_entry.grid(row=0, column=1, sticky=tk.W, pady=5)
         
        password_label = ttk.Label(form_frame, text="Password:", style='TLabel')
        password_label.grid(row=1, column=0, sticky=tk.W, pady=5)
         
        password_entry = ttk.Entry(form_frame, width=30, show="*")
        password_entry.grid(row=1, column=1, sticky=tk.W, pady=5)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color, style='TLabel')
        error_label.grid(row=2, column=0, columnspan=2, sticky=tk.W, pady=5)
         
        # Buttons
        button_frame = ttk.Frame(form_frame, style='TFrame')
        button_frame.grid(row=3, column=0, columnspan=2, pady=20)
         
        login_button = ttk.Button(button_frame, text="Login", command=lambda: self.login(username_entry.get(), password_entry.get(), error_label))
        login_button.pack(side=tk.LEFT, padx=5)
         
        register_button = ttk.Button(button_frame, text="Register", command=self.show_register)
        register_button.pack(side=tk.LEFT, padx=5)
         
        # Add some demo credentials for testing
        demo_frame = ttk.Frame(login_frame, style='TFrame')
        demo_frame.pack(pady=10)
         
        demo_label = ttk.Label(demo_frame, text="Demo: username 'admin', password 'admin123'", font=("Helvetica", 8), style='TLabel')
        demo_label.pack()
         
        # Display the frame with animation
        self.animate_frame(login_frame)
     
    def login(self, username, password, error_label):
        """Validate login credentials and log user in"""
        if not username or not password:
            error_label.config(text="Username and password are required")
            return
         
        # Hash the password
        hashed_password = hashlib.sha256(password.encode()).hexdigest()
         
        # Check credentials
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute("SELECT * FROM users WHERE username = ? AND password = ?", (username, hashed_password))
        user = cursor.fetchone()
         
        if user:
            self.current_user = {
                'id': user[0],
                'username': user[1],
                'full_name': user[3],
                'email': user[4],
                'phone': user[5],
                'address': user[6],
                'registration_date': user[7]
            }
            conn.close()
            self.show_dashboard()
        else:
            conn.close()
            error_label.config(text="Invalid username or password")
     
    def show_register(self):
        """Display the registration frame"""
        register_frame = ttk.Frame(self.root, style='TFrame')
         
        # Title
        title_label = ttk.Label(register_frame, text="Create New Account", font=("Helvetica", 24, "bold"), style='TLabel')
        title_label.pack(pady=20)
         
        # Registration form
        form_frame = ttk.Frame(register_frame, style='TFrame')
        form_frame.pack(pady=10, padx=50, fill=tk.X)
         
        # Username
        username_label = ttk.Label(form_frame, text="Username:", style='TLabel')
        username_label.grid(row=0, column=0, sticky=tk.W, pady=5)
         
        username_entry = ttk.Entry(form_frame, width=30)
        username_entry.grid(row=0, column=1, sticky=tk.W, pady=5)
         
        # Password
        password_label = ttk.Label(form_frame, text="Password:", style='TLabel')
        password_label.grid(row=1, column=0, sticky=tk.W, pady=5)
         
        password_entry = ttk.Entry(form_frame, width=30, show="*")
        password_entry.grid(row=1, column=1, sticky=tk.W, pady=5)
         
        # Confirm Password
        conf_password_label = ttk.Label(form_frame, text="Confirm Password:", style='TLabel')
        conf_password_label.grid(row=2, column=0, sticky=tk.W, pady=5)
         
        conf_password_entry = ttk.Entry(form_frame, width=30, show="*")
        conf_password_entry.grid(row=2, column=1, sticky=tk.W, pady=5)
         
        # Full Name
        fullname_label = ttk.Label(form_frame, text="Full Name:", style='TLabel')
        fullname_label.grid(row=3, column=0, sticky=tk.W, pady=5)
         
        fullname_entry = ttk.Entry(form_frame, width=30)
        fullname_entry.grid(row=3, column=1, sticky=tk.W, pady=5)
         
        # Email
        email_label = ttk.Label(form_frame, text="Email:", style='TLabel')
        email_label.grid(row=4, column=0, sticky=tk.W, pady=5)
         
        email_entry = ttk.Entry(form_frame, width=30)
        email_entry.grid(row=4, column=1, sticky=tk.W, pady=5)
         
        # Phone
        phone_label = ttk.Label(form_frame, text="Phone:", style='TLabel')
        phone_label.grid(row=5, column=0, sticky=tk.W, pady=5)
         
        phone_entry = ttk.Entry(form_frame, width=30)
        phone_entry.grid(row=5, column=1, sticky=tk.W, pady=5)
         
        # Address
        address_label = ttk.Label(form_frame, text="Address:", style='TLabel')
        address_label.grid(row=6, column=0, sticky=tk.W, pady=5)
         
        address_entry = ttk.Entry(form_frame, width=30)
        address_entry.grid(row=6, column=1, sticky=tk.W, pady=5)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color, style='TLabel')
        error_label.grid(row=7, column=0, columnspan=2, sticky=tk.W, pady=5)
         
        # Buttons
        button_frame = ttk.Frame(form_frame, style='TFrame')
        button_frame.grid(row=8, column=0, columnspan=2, pady=20)
         
        register_button = ttk.Button(
            button_frame,
            text="Register",
            command=lambda: self.register_user(
                username_entry.get(),
                password_entry.get(),
                conf_password_entry.get(),
                fullname_entry.get(),
                email_entry.get(),
                phone_entry.get(),
                address_entry.get(),
                error_label
            )
        )
        register_button.pack(side=tk.LEFT, padx=5)
         
        back_button = ttk.Button(button_frame, text="Back to Login", command=self.show_login)
        back_button.pack(side=tk.LEFT, padx=5)
         
        # Display the frame with animation
        self.animate_frame(register_frame, "left")
     
    def register_user(self, username, password, conf_password, fullname, email, phone, address, error_label):
        """Register a new user"""
        # Validate fields
        if not all([username, password, conf_password, fullname, email]):
            error_label.config(text="All fields marked with * are required")
            return
         
        if password != conf_password:
            error_label.config(text="Passwords do not match")
            return
         
        # Hash the password
        hashed_password = hashlib.sha256(password.encode()).hexdigest()
         
        # Get current date
        registration_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
         
        # Save to database
        try:
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            cursor.execute('''
            INSERT INTO users (username, password, full_name, email, phone, address, registration_date)
            VALUES (?, ?, ?, ?, ?, ?, ?)
            ''', (username, hashed_password, fullname, email, phone, address, registration_date))
             
            conn.commit()
            conn.close()
             
            messagebox.showinfo("Success", "Registration successful. Please login.")
            self.show_login()
        except sqlite3.IntegrityError:
            error_label.config(text="Username or email already exists")
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def show_dashboard(self):
        """Display the main dashboard"""
        dashboard_frame = ttk.Frame(self.root, style='TFrame')
         
        # Create top bar
        top_bar = ttk.Frame(dashboard_frame, style='TFrame')
        top_bar.pack(fill=tk.X, padx=10, pady=10)
         
        # Welcome message
        welcome_label = ttk.Label(top_bar, text=f"Welcome, {self.current_user['full_name']}", font=("Helvetica", 16, "bold"), style='TLabel')
        welcome_label.pack(side=tk.LEFT)
         
        # Logout button
        logout_button = ttk.Button(top_bar, text="Logout", command=self.logout)
        logout_button.pack(side=tk.RIGHT)
         
        # Create sidebar and main content area
        content_frame = ttk.Frame(dashboard_frame, style='TFrame')
        content_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
         
        sidebar = ttk.Frame(content_frame, width=200, style='TFrame')
        sidebar.pack(side=tk.LEFT, fill=tk.Y, padx=(0, 10))
         
        # Ensure sidebar maintains its width
        sidebar.pack_propagate(False)
         
        # Main content area
        main_content = ttk.Frame(content_frame, style='TFrame')
        main_content.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
         
        # Add menu buttons to sidebar
        home_btn_frame = self.create_custom_button(sidebar, "Dashboard", lambda: self.load_dashboard_content(main_content), icon="home")
        home_btn_frame.pack(fill=tk.X, pady=5)
         
        accounts_btn_frame = self.create_custom_button(sidebar, "Accounts", lambda: self.load_accounts_content(main_content), icon="account")
        accounts_btn_frame.pack(fill=tk.X, pady=5)
         
        transactions_btn_frame = self.create_custom_button(sidebar, "Transactions", lambda: self.load_transactions_content(main_content), icon="transaction")
        transactions_btn_frame.pack(fill=tk.X, pady=5)
         
        profile_btn_frame = self.create_custom_button(sidebar, "Profile", lambda: self.load_profile_content(main_content), icon="user")
        profile_btn_frame.pack(fill=tk.X, pady=5)
         
        # Load dashboard content by default
        self.load_dashboard_content(main_content)
         
        # Display the frame with animation
        self.animate_frame(dashboard_frame)
     
    def load_dashboard_content(self, parent):
        """Load dashboard overview content"""
        # Clear previous content
        for widget in parent.winfo_children():
            widget.destroy()
         
        # Add title
        title_label = ttk.Label(parent, text="Dashboard Overview", font=("Helvetica", 16, "bold"), style='TLabel')
        title_label.pack(pady=10, anchor=tk.W)
         
        # Create stats section
        stats_frame = ttk.Frame(parent, style='TFrame')
        stats_frame.pack(fill=tk.X, pady=10)
         
        # Fetch account summary
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        # Get accounts
        cursor.execute('''
        SELECT id, account_number, account_type, balance, status
        FROM accounts
        WHERE user_id = ?
        ''', (self.current_user['id'],))
         
        accounts = cursor.fetchall()
         
        # Get total balance
        total_balance = sum(account[3] for account in accounts)
         
        # Get recent transactions
        cursor.execute('''
        SELECT t.* FROM transactions t
        JOIN accounts a ON t.account_id = a.id
        WHERE a.user_id = ?
        ORDER BY t.transaction_date DESC
        LIMIT 5
        ''', (self.current_user['id'],))
         
        recent_transactions = cursor.fetchall()
         
        conn.close()
         
        # Create stats cards
        card_frame = ttk.Frame(stats_frame, style='TFrame')
        card_frame.pack(fill=tk.X)
         
        # Card 1: Total Balance
        balance_card = ttk.Frame(card_frame, style='TFrame')
        balance_card.pack(side=tk.LEFT, padx=10, fill=tk.X, expand=True)
         
        balance_canvas = tk.Canvas(balance_card, width=200, height=100, bg=self.primary_color, highlightthickness=0)
        balance_canvas.pack(fill=tk.BOTH, expand=True)
         
        balance_canvas.create_text(100, 30, text="Total Balance", fill="white", font=("Helvetica", 12))
        balance_canvas.create_text(100, 60, text=f"${total_balance:.2f}", fill="white", font=("Helvetica", 18, "bold"))
         
        # Card 2: Number of Accounts
        accounts_card = ttk.Frame(card_frame, style='TFrame')
        accounts_card.pack(side=tk.LEFT, padx=10, fill=tk.X, expand=True)
         
        accounts_canvas = tk.Canvas(accounts_card, width=200, height=100, bg=self.accent_color, highlightthickness=0)
        accounts_canvas.pack(fill=tk.BOTH, expand=True)
         
        accounts_canvas.create_text(100, 30, text="Total Accounts", fill="white", font=("Helvetica", 12))
        accounts_canvas.create_text(100, 60, text=str(len(accounts)), fill="white", font=("Helvetica", 18, "bold"))
         
        # Card 3: Recent Activity
        activity_card = ttk.Frame(card_frame, style='TFrame')
        activity_card.pack(side=tk.LEFT, padx=10, fill=tk.X, expand=True)
         
        activity_canvas = tk.Canvas(activity_card, width=200, height=100, bg=self.success_color, highlightthickness=0)
        activity_canvas.pack(fill=tk.BOTH, expand=True)
         
        activity_canvas.create_text(100, 30, text="Recent Activity", fill="white", font=("Helvetica", 12))
        activity_canvas.create_text(100, 60, text=f"{len(recent_transactions)} transactions", fill="white", font=("Helvetica", 18, "bold"))
         
        # Quick Actions section
        actions_frame = ttk.Frame(parent, style='TFrame')
        actions_frame.pack(fill=tk.X, pady=20)
         
        actions_label = ttk.Label(actions_frame, text="Quick Actions", font=("Helvetica", 14, "bold"), style='TLabel')
        actions_label.pack(anchor=tk.W, pady=(0, 10))
         
        buttons_frame = ttk.Frame(actions_frame, style='TFrame')
        buttons_frame.pack(fill=tk.X)
         
        new_account_btn = ttk.Button(buttons_frame, text="New Account", command=lambda: self.show_new_account_dialog())
        new_account_btn.pack(side=tk.LEFT, padx=5)
         
        deposit_btn = ttk.Button(buttons_frame, text="Deposit", command=lambda: self.show_deposit_dialog())
        deposit_btn.pack(side=tk.LEFT, padx=5)
         
        withdraw_btn = ttk.Button(buttons_frame, text="Withdraw", command=lambda: self.show_withdraw_dialog())
        withdraw_btn.pack(side=tk.LEFT, padx=5)
         
        transfer_btn = ttk.Button(buttons_frame, text="Transfer", command=lambda: self.show_transfer_dialog())
        transfer_btn.pack(side=tk.LEFT, padx=5)
         
        # Recent Transactions section
        transactions_frame = ttk.Frame(parent, style='TFrame')
        transactions_frame.pack(fill=tk.BOTH, expand=True, pady=10)
         
        transactions_label = ttk.Label(transactions_frame, text="Recent Transactions", font=("Helvetica", 14, "bold"), style='TLabel')
        transactions_label.pack(anchor=tk.W, pady=(0, 10))
         
        # Create a treeview for transactions
        columns = ("date", "type", "amount", "description", "status")
        tree = ttk.Treeview(transactions_frame, columns=columns, show="headings")
         
        # Define headings
        tree.heading("date", text="Date")
        tree.heading("type", text="Type")
        tree.heading("amount", text="Amount")
        tree.heading("description", text="Description")
        tree.heading("status", text="Status")
         
        # Define columns
        tree.column("date", width=150)
        tree.column("type", width=100)
        tree.column("amount", width=100)
        tree.column("description", width=200)
        tree.column("status", width=100)
         
        # Add a scrollbar
        scrollbar = ttk.Scrollbar(transactions_frame, orient=tk.VERTICAL, command=tree.yview)
        tree.configure(yscroll=scrollbar.set)
        scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        tree.pack(fill=tk.BOTH, expand=True)
         
        # Populate the treeview with transactions
        for transaction in recent_transactions:
            transaction_id = transaction[0]
            transaction_type = transaction[2]
            amount = transaction[3]
            description = transaction[4]
            transaction_date = transaction[5]
            status = transaction[7]
             
            tree.insert("", tk.END, values=(transaction_date, transaction_type, f"${amount:.2f}", description, status))
     
    def load_accounts_content(self, parent):
        """Load accounts management content"""
        # Clear previous content
        for widget in parent.winfo_children():
            widget.destroy()
         
        # Add title
        title_label = ttk.Label(parent, text="Accounts Management", font=("Helvetica", 16, "bold"), style='TLabel')
        title_label.pack(pady=10, anchor=tk.W)
         
        # Create action buttons
        buttons_frame = ttk.Frame(parent, style='TFrame')
        buttons_frame.pack(fill=tk.X, pady=10)
         
        new_account_btn = ttk.Button(buttons_frame, text="New Account", command=lambda: self.show_new_account_dialog())
        new_account_btn.pack(side=tk.LEFT, padx=5)
         
        refresh_btn = ttk.Button(buttons_frame, text="Refresh", command=lambda: self.load_accounts_content(parent))
        refresh_btn.pack(side=tk.LEFT, padx=5)
         
        # Create accounts list
        accounts_frame = ttk.Frame(parent, style='TFrame')
        accounts_frame.pack(fill=tk.BOTH, expand=True, pady=10)
         
        # Create a treeview for accounts
        columns = ("number", "type", "balance", "status", "opening_date")
        tree = ttk.Treeview(accounts_frame, columns=columns, show="headings")
         
        # Define headings
        tree.heading("number", text="Account Number")
        tree.heading("type", text="Type")
        tree.heading("balance", text="Balance")
        tree.heading("status", text="Status")
        tree.heading("opening_date", text="Opening Date")
         
        # Define columns
        tree.column("number", width=150)
        tree.column("type", width=100)
        tree.column("balance", width=100)
        tree.column("status", width=100)
        tree.column("opening_date", width=150)
         
        # Add a scrollbar
        scrollbar = ttk.Scrollbar(accounts_frame, orient=tk.VERTICAL, command=tree.yview)
        tree.configure(yscroll=scrollbar.set)
        scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        tree.pack(fill=tk.BOTH, expand=True)
         
        # Fetch accounts
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT id, account_number, account_type, balance, opening_date, status
        FROM accounts
        WHERE user_id = ?
        ''', (self.current_user['id'],))
         
        accounts = cursor.fetchall()
        conn.close()
         
        # Populate the treeview with accounts
        for account in accounts:
            account_id = account[0]
            number = account[1]
            account_type = account[2]
            balance = account[3]
            opening_date = account[4]
            status = account[5]
             
            tree.insert("", tk.END, iid=account_id, values=(number, account_type, f"${balance:.2f}", status, opening_date))
         
        # Add right-click menu
        menu = tk.Menu(tree, tearoff=0)
        menu.add_command(label="View Details", command=lambda: self.view_account_details(tree.focus()))
        menu.add_command(label="Deposit", command=lambda: self.show_deposit_dialog(tree.focus()))
        menu.add_command(label="Withdraw", command=lambda: self.show_withdraw_dialog(tree.focus()))
        menu.add_command(label="Close Account", command=lambda: self.close_account(tree.focus()))
         
        def show_menu(event):
            if tree.focus():  # Only show menu if an item is selected
                menu.post(event.x_root, event.y_root)
         
        tree.bind("<Button-3>", show_menu)  # Right-click
        tree.bind("<Double-1>", lambda event: self.view_account_details(tree.focus()))  # Double-click
     
    def load_transactions_content(self, parent):
        """Load transactions history content"""
        # Clear previous content
        for widget in parent.winfo_children():
            widget.destroy()
         
        # Add title
        title_label = ttk.Label(parent, text="Transaction History", font=("Helvetica", 16, "bold"), style='TLabel')
        title_label.pack(pady=10, anchor=tk.W)
         
        # Create filter section
        filter_frame = ttk.Frame(parent, style='TFrame')
        filter_frame.pack(fill=tk.X, pady=10)
         
        # Account filter
        account_label = ttk.Label(filter_frame, text="Account:", style='TLabel')
        account_label.pack(side=tk.LEFT, padx=5)
         
        account_var = tk.StringVar()
        account_var.set("All Accounts")
         
        # Fetch accounts for the dropdown
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT id, account_number, account_type
        FROM accounts
        WHERE user_id = ?
        ''', (self.current_user['id'],))
         
        accounts = cursor.fetchall()
        account_options = ["All Accounts"] + [f"{account[1]} ({account[2]})" for account in accounts]
         
        account_dropdown = ttk.Combobox(filter_frame, textvariable=account_var, values=account_options, state="readonly")
        account_dropdown.pack(side=tk.LEFT, padx=5)
         
        # Type filter
        type_label = ttk.Label(filter_frame, text="Type:", style='TLabel')
        type_label.pack(side=tk.LEFT, padx=5)
         
        type_var = tk.StringVar()
        type_var.set("All Types")
         
        type_options = ["All Types", "Deposit", "Withdrawal", "Transfer"]
        type_dropdown = ttk.Combobox(filter_frame, textvariable=type_var, values=type_options, state="readonly")
        type_dropdown.pack(side=tk.LEFT, padx=5)
         
        # Apply button
        apply_btn = ttk.Button(filter_frame, text="Apply Filter", command=lambda: self.apply_transaction_filters(parent, account_var.get(), type_var.get()))
        apply_btn.pack(side=tk.LEFT, padx=5)
         
        # Create transactions list
        transactions_frame = ttk.Frame(parent, style='TFrame')
        transactions_frame.pack(fill=tk.BOTH, expand=True, pady=10)
         
        # Create a treeview for transactions
        columns = ("date", "account", "type", "amount", "description", "reference", "status")
        tree = ttk.Treeview(transactions_frame, columns=columns, show="headings")
         
        # Define headings
        tree.heading("date", text="Date")
        tree.heading("account", text="Account")
        tree.heading("type", text="Type")
        tree.heading("amount", text="Amount")
        tree.heading("description", text="Description")
        tree.heading("reference", text="Reference")
        tree.heading("status", text="Status")
         
        # Define columns
        tree.column("date", width=150)
        tree.column("account", width=150)
        tree.column("type", width=100)
        tree.column("amount", width=100)
        tree.column("description", width=200)
        tree.column("reference", width=100)
        tree.column("status", width=100)
         
        # Add a scrollbar
        scrollbar = ttk.Scrollbar(transactions_frame, orient=tk.VERTICAL, command=tree.yview)
        tree.configure(yscroll=scrollbar.set)
        scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        tree.pack(fill=tk.BOTH, expand=True)
         
        # Fetch all transactions for the user
        cursor.execute('''
        SELECT t.*, a.account_number
        FROM transactions t
        JOIN accounts a ON t.account_id = a.id
        WHERE a.user_id = ?
        ORDER BY t.transaction_date DESC
        ''', (self.current_user['id'],))
         
        transactions = cursor.fetchall()
        conn.close()
         
        # Populate the treeview with transactions
        for transaction in transactions:
            transaction_id = transaction[0]
            account_number = transaction[8]
            transaction_type = transaction[2]
            amount = transaction[3]
            description = transaction[4]
            transaction_date = transaction[5]
            reference = transaction[6]
            status = transaction[7]
             
            tree.insert("", tk.END, iid=transaction_id, values=(transaction_date, account_number, transaction_type, f"${amount:.2f}", description, reference, status))
         
        # Add double-click to view details
        tree.bind("<Double-1>", lambda event: self.view_transaction_details(tree.focus()))
     
    def apply_transaction_filters(self, parent, account_filter, type_filter):
        """Apply filters to transaction history"""
        # Reload the content with filters
        self.load_transactions_content(parent)  # This is a simplified version, in reality you'd modify the query
     
    def load_profile_content(self, parent):
        """Load user profile content"""
        # Clear previous content
        for widget in parent.winfo_children():
            widget.destroy()
         
        # Add title
        title_label = ttk.Label(parent, text="User Profile", font=("Helvetica", 16, "bold"), style='TLabel')
        title_label.pack(pady=10, anchor=tk.W)
         
        # Create profile section
        profile_frame = ttk.Frame(parent, style='TFrame')
        profile_frame.pack(fill=tk.BOTH, expand=True, pady=10)
         
        # Profile picture frame
        pic_frame = ttk.Frame(profile_frame, style='TFrame')
        pic_frame.pack(side=tk.LEFT, padx=20, pady=20)
         
        # Create a circular avatar
        canvas = tk.Canvas(pic_frame, width=120, height=120, bg=self.secondary_color, highlightthickness=0)
        canvas.create_oval(10, 10, 110, 110, fill=self.primary_color, outline="")
        canvas.create_text(60, 60, text=self.current_user['full_name'][0].upper(), fill="white", font=("Helvetica", 36, "bold"))
        canvas.pack()
         
        # User info section
        info_frame = ttk.Frame(profile_frame, style='TFrame')
        info_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=20, pady=20)
         
        # Full Name
        name_label = ttk.Label(info_frame, text="Full Name:", font=("Helvetica", 10, "bold"), style='TLabel')
        name_label.grid(row=0, column=0, sticky=tk.W, pady=5)
         
        name_value = ttk.Label(info_frame, text=self.current_user['full_name'], style='TLabel')
        name_value.grid(row=0, column=1, sticky=tk.W, pady=5)
         
        # Username
        username_label = ttk.Label(info_frame, text="Username:", font=("Helvetica", 10, "bold"), style='TLabel')
        username_label.grid(row=1, column=0, sticky=tk.W, pady=5)
         
        username_value = ttk.Label(info_frame, text=self.current_user['username'], style='TLabel')
        username_value.grid(row=1, column=1, sticky=tk.W, pady=5)
         
        # Email
        email_label = ttk.Label(info_frame, text="Email:", font=("Helvetica", 10, "bold"), style='TLabel')
        email_label.grid(row=2, column=0, sticky=tk.W, pady=5)
         
        email_value = ttk.Label(info_frame, text=self.current_user['email'], style='TLabel')
        email_value.grid(row=2, column=1, sticky=tk.W, pady=5)
         
        # Phone
        phone_label = ttk.Label(info_frame, text="Phone:", font=("Helvetica", 10, "bold"), style='TLabel')
        phone_label.grid(row=3, column=0, sticky=tk.W, pady=5)
         
        phone_value = ttk.Label(info_frame, text=self.current_user['phone'] or "Not provided", style='TLabel')
        phone_value.grid(row=3, column=1, sticky=tk.W, pady=5)
         
        # Address
        address_label = ttk.Label(info_frame, text="Address:", font=("Helvetica", 10, "bold"), style='TLabel')
        address_label.grid(row=4, column=0, sticky=tk.W, pady=5)
         
        address_value = ttk.Label(info_frame, text=self.current_user['address'] or "Not provided", style='TLabel')
        address_value.grid(row=4, column=1, sticky=tk.W, pady=5)
         
        # Registration Date
        reg_date_label = ttk.Label(info_frame, text="Registration Date:", font=("Helvetica", 10, "bold"), style='TLabel')
        reg_date_label.grid(row=5, column=0, sticky=tk.W, pady=5)
         
        reg_date_value = ttk.Label(info_frame, text=self.current_user['registration_date'], style='TLabel')
        reg_date_value.grid(row=5, column=1, sticky=tk.W, pady=5)
         
        # Edit profile button
        edit_button = ttk.Button(info_frame, text="Edit Profile", command=self.show_edit_profile_dialog)
        edit_button.grid(row=6, column=0, columnspan=2, sticky=tk.W, pady=20)
         
        # Change password button
        change_pwd_button = ttk.Button(info_frame, text="Change Password", command=self.show_change_password_dialog)
        change_pwd_button.grid(row=6, column=1, sticky=tk.E, pady=20)
     
    def show_new_account_dialog(self):
        """Show dialog to create a new account"""
        dialog = tk.Toplevel(self.root)
        dialog.title("Create New Account")
        dialog.geometry("400x300")
        dialog.resizable(False, False)
        dialog.transient(self.root)
        dialog.grab_set()
         
        # Create form
        form_frame = ttk.Frame(dialog)
        form_frame.pack(padx=20, pady=20, fill=tk.BOTH, expand=True)
         
        # Account Type
        type_label = ttk.Label(form_frame, text="Account Type:")
        type_label.grid(row=0, column=0, sticky=tk.W, pady=10)
         
        type_var = tk.StringVar()
        type_var.set("Savings")
         
        type_options = ["Savings", "Checking", "Fixed Deposit", "Loan"]
        type_dropdown = ttk.Combobox(form_frame, textvariable=type_var, values=type_options, state="readonly")
        type_dropdown.grid(row=0, column=1, sticky=tk.W, pady=10)
         
        # Initial Deposit
        deposit_label = ttk.Label(form_frame, text="Initial Deposit:")
        deposit_label.grid(row=1, column=0, sticky=tk.W, pady=10)
         
        deposit_entry = ttk.Entry(form_frame)
        deposit_entry.grid(row=1, column=1, sticky=tk.W, pady=10)
        deposit_entry.insert(0, "0.00")
         
        # Description
        desc_label = ttk.Label(form_frame, text="Description (Optional):")
        desc_label.grid(row=2, column=0, sticky=tk.W, pady=10)
         
        desc_entry = ttk.Entry(form_frame)
        desc_entry.grid(row=2, column=1, sticky=tk.W, pady=10)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color)
        error_label.grid(row=3, column=0, columnspan=2, sticky=tk.W, pady=10)
         
        # Buttons
        button_frame = ttk.Frame(form_frame)
        button_frame.grid(row=4, column=0, columnspan=2, pady=20)
         
        create_button = ttk.Button(
            button_frame,
            text="Create Account",
            command=lambda: self.create_new_account(
                type_var.get(),
                deposit_entry.get(),
                desc_entry.get(),
                error_label,
                dialog
            )
        )
        create_button.pack(side=tk.LEFT, padx=5)
         
        cancel_button = ttk.Button(button_frame, text="Cancel", command=dialog.destroy)
        cancel_button.pack(side=tk.LEFT, padx=5)
     
    def create_new_account(self, account_type, initial_deposit, description, error_label, dialog):
        """Create a new bank account"""
        try:
            # Validate initial deposit
            initial_deposit = float(initial_deposit)
            if initial_deposit < 0:
                error_label.config(text="Initial deposit cannot be negative")
                return
             
            # Generate account number
            account_number = f"{random.randint(10000, 99999)}-{random.randint(10000, 99999)}"
             
            # Get current date
            opening_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
             
            # Save to database
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            cursor.execute('''
            INSERT INTO accounts (user_id, account_number, account_type, balance, opening_date, status)
            VALUES (?, ?, ?, ?, ?, ?)
            ''', (self.current_user['id'], account_number, account_type, initial_deposit, opening_date, "active"))
             
            # Get the new account ID
            account_id = cursor.lastrowid
             
            # If there's an initial deposit, create a transaction
            if initial_deposit > 0:
                reference_number = f"DEP-{random.randint(1000000, 9999999)}"
                 
                cursor.execute('''
                INSERT INTO transactions (account_id, transaction_type, amount, description, transaction_date, reference_number, status)
                VALUES (?, ?, ?, ?, ?, ?, ?)
                ''', (account_id, "Deposit", initial_deposit, "Initial deposit", opening_date, reference_number, "completed"))
             
            conn.commit()
            conn.close()
             
            messagebox.showinfo("Success", f"New {account_type} account created successfully!")
            dialog.destroy()
             
            # Refresh the accounts view if it's open
            if self.current_frame:
                main_content = None
                for widget in self.current_frame.winfo_children():
                    if isinstance(widget, ttk.Frame) and widget.winfo_children():
                        for child in widget.winfo_children():
                            if isinstance(child, ttk.Frame) and child.winfo_width() > 200:
                                main_content = child
                                break
                 
                if main_content:
                    self.load_accounts_content(main_content)
        except ValueError:
            error_label.config(text="Please enter a valid amount for initial deposit")
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def show_deposit_dialog(self, account_id=None):
        """Show dialog to make a deposit"""
        dialog = tk.Toplevel(self.root)
        dialog.title("Make a Deposit")
        dialog.geometry("400x300")
        dialog.resizable(False, False)
        dialog.transient(self.root)
        dialog.grab_set()
         
        # Create form
        form_frame = ttk.Frame(dialog)
        form_frame.pack(padx=20, pady=20, fill=tk.BOTH, expand=True)
         
        # Account selection
        account_label = ttk.Label(form_frame, text="Select Account:")
        account_label.grid(row=0, column=0, sticky=tk.W, pady=10)
         
        # Fetch accounts
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT id, account_number, account_type, balance
        FROM accounts
        WHERE user_id = ? AND status = 'active'
        ''', (self.current_user['id'],))
         
        accounts = cursor.fetchall()
        conn.close()
         
        account_var = tk.StringVar()
        account_options = [f"{account[1]} ({account[2]}) - ${account[3]:.2f}" for account in accounts]
        account_ids = [account[0] for account in accounts]
         
        if account_id and account_id in account_ids:
            index = account_ids.index(account_id)
            account_var.set(account_options[index])
        elif account_options:
            account_var.set(account_options[0])
         
        account_dropdown = ttk.Combobox(form_frame, textvariable=account_var, values=account_options, state="readonly")
        account_dropdown.grid(row=0, column=1, sticky=tk.W, pady=10)
         
        # Amount
        amount_label = ttk.Label(form_frame, text="Amount:")
        amount_label.grid(row=1, column=0, sticky=tk.W, pady=10)
         
        amount_entry = ttk.Entry(form_frame)
        amount_entry.grid(row=1, column=1, sticky=tk.W, pady=10)
         
        # Description
        desc_label = ttk.Label(form_frame, text="Description (Optional):")
        desc_label.grid(row=2, column=0, sticky=tk.W, pady=10)
         
        desc_entry = ttk.Entry(form_frame)
        desc_entry.grid(row=2, column=1, sticky=tk.W, pady=10)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color)
        error_label.grid(row=3, column=0, columnspan=2, sticky=tk.W, pady=10)
         
        # Buttons
        button_frame = ttk.Frame(form_frame)
        button_frame.grid(row=4, column=0, columnspan=2, pady=20)
         
        deposit_button = ttk.Button(
            button_frame,
            text="Make Deposit",
            command=lambda: self.make_deposit(
                account_var.get(),
                amount_entry.get(),
                desc_entry.get(),
                error_label,
                dialog,
                account_ids,
                account_options
            )
        )
        deposit_button.pack(side=tk.LEFT, padx=5)
         
        cancel_button = ttk.Button(button_frame, text="Cancel", command=dialog.destroy)
        cancel_button.pack(side=tk.LEFT, padx=5)
     
    def make_deposit(self, account_option, amount, description, error_label, dialog, account_ids, account_options):
        """Process a deposit transaction"""
        try:
            # Validate amount
            amount = float(amount)
            if amount <= 0:
                error_label.config(text="Amount must be positive")
                return
             
            # Get account ID
            account_index = account_options.index(account_option)
            account_id = account_ids[account_index]
             
            # Set default description if none provided
            if not description:
                description = "Deposit"
             
            # Generate reference number
            reference_number = f"DEP-{random.randint(1000000, 9999999)}"
             
            # Get current date
            transaction_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
             
            # Update database
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            # Add transaction
            cursor.execute('''
            INSERT INTO transactions (account_id, transaction_type, amount, description, transaction_date, reference_number, status)
            VALUES (?, ?, ?, ?, ?, ?, ?)
            ''', (account_id, "Deposit", amount, description, transaction_date, reference_number, "completed"))
             
            # Update account balance
            cursor.execute('''
            UPDATE accounts SET balance = balance + ? WHERE id = ?
            ''', (amount, account_id))
             
            conn.commit()
            conn.close()
             
            messagebox.showinfo("Success", f"Deposit of ${amount:.2f} completed successfully!")
            dialog.destroy()
             
            # Refresh the relevant view if it's open
            if self.current_frame:
                main_content = None
                for widget in self.current_frame.winfo_children():
                    if isinstance(widget, ttk.Frame) and widget.winfo_children():
                        for child in widget.winfo_children():
                            if isinstance(child, ttk.Frame) and child.winfo_width() > 200:
                                main_content = child
                                break
                 
                if main_content:
                    # Try to determine which view is open and refresh it
                    title_widget = None
                    for widget in main_content.winfo_children():
                        if isinstance(widget, ttk.Label) and widget.cget("text") in ["Dashboard Overview", "Accounts Management", "Transaction History"]:
                            title_widget = widget
                            break
                     
                    if title_widget:
                        if title_widget.cget("text") == "Dashboard Overview":
                            self.load_dashboard_content(main_content)
                        elif title_widget.cget("text") == "Accounts Management":
                            self.load_accounts_content(main_content)
                        elif title_widget.cget("text") == "Transaction History":
                            self.load_transactions_content(main_content)
        except ValueError:
            error_label.config(text="Please enter a valid amount")
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def show_withdraw_dialog(self, account_id=None):
        """Show dialog to make a withdrawal"""
        dialog = tk.Toplevel(self.root)
        dialog.title("Make a Withdrawal")
        dialog.geometry("400x300")
        dialog.resizable(False, False)
        dialog.transient(self.root)
        dialog.grab_set()
         
        # Create form
        form_frame = ttk.Frame(dialog)
        form_frame.pack(padx=20, pady=20, fill=tk.BOTH, expand=True)
         
        # Account selection
        account_label = ttk.Label(form_frame, text="Select Account:")
        account_label.grid(row=0, column=0, sticky=tk.W, pady=10)
         
        # Fetch accounts
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT id, account_number, account_type, balance
        FROM accounts
        WHERE user_id = ? AND status = 'active'
        ''', (self.current_user['id'],))
         
        accounts = cursor.fetchall()
        conn.close()
         
        account_var = tk.StringVar()
        account_options = [f"{account[1]} ({account[2]}) - ${account[3]:.2f}" for account in accounts]
        account_ids = [account[0] for account in accounts]
         
        if account_id and account_id in account_ids:
            index = account_ids.index(account_id)
            account_var.set(account_options[index])
        elif account_options:
            account_var.set(account_options[0])
         
        account_dropdown = ttk.Combobox(form_frame, textvariable=account_var, values=account_options, state="readonly")
        account_dropdown.grid(row=0, column=1, sticky=tk.W, pady=10)
         
        # Amount
        amount_label = ttk.Label(form_frame, text="Amount:")
        amount_label.grid(row=1, column=0, sticky=tk.W, pady=10)
         
        amount_entry = ttk.Entry(form_frame)
        amount_entry.grid(row=1, column=1, sticky=tk.W, pady=10)
         
        # Description
        desc_label = ttk.Label(form_frame, text="Description (Optional):")
        desc_label.grid(row=2, column=0, sticky=tk.W, pady=10)
         
        desc_entry = ttk.Entry(form_frame)
        desc_entry.grid(row=2, column=1, sticky=tk.W, pady=10)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color)
        error_label.grid(row=3, column=0, columnspan=2, sticky=tk.W, pady=10)
         
        # Buttons
        button_frame = ttk.Frame(form_frame)
        button_frame.grid(row=4, column=0, columnspan=2, pady=20)
         
        withdraw_button = ttk.Button(
            button_frame,
            text="Make Withdrawal",
            command=lambda: self.make_withdrawal(
                account_var.get(),
                amount_entry.get(),
                desc_entry.get(),
                error_label,
                dialog,
                account_ids,
                account_options,
                accounts
            )
        )
        withdraw_button.pack(side=tk.LEFT, padx=5)
         
        cancel_button = ttk.Button(button_frame, text="Cancel", command=dialog.destroy)
        cancel_button.pack(side=tk.LEFT, padx=5)
     
    def make_withdrawal(self, account_option, amount, description, error_label, dialog, account_ids, account_options, accounts):
        """Process a withdrawal transaction"""
        try:
            # Validate amount
            amount = float(amount)
            if amount <= 0:
                error_label.config(text="Amount must be positive")
                return
             
            # Get account ID and balance
            account_index = account_options.index(account_option)
            account_id = account_ids[account_index]
            account_balance = accounts[account_index][3]
             
            # Check if sufficient balance
            if amount > account_balance:
                error_label.config(text="Insufficient balance")
                return
             
            # Set default description if none provided
            if not description:
                description = "Withdrawal"
             
            # Generate reference number
            reference_number = f"WDR-{random.randint(1000000, 9999999)}"
             
            # Get current date
            transaction_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
             
            # Update database
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            # Add transaction
            cursor.execute('''
            INSERT INTO transactions (account_id, transaction_type, amount, description, transaction_date, reference_number, status)
            VALUES (?, ?, ?, ?, ?, ?, ?)
            ''', (account_id, "Withdrawal", amount, description, transaction_date, reference_number, "completed"))
             
            # Update account balance
            cursor.execute('''
            UPDATE accounts SET balance = balance - ? WHERE id = ?
            ''', (amount, account_id))
             
            conn.commit()
            conn.close()
             
            messagebox.showinfo("Success", f"Withdrawal of ${amount:.2f} completed successfully!")
            dialog.destroy()
             
            # Refresh the relevant view if it's open
            if self.current_frame:
                main_content = None
                for widget in self.current_frame.winfo_children():
                    if isinstance(widget, ttk.Frame) and widget.winfo_children():
                        for child in widget.winfo_children():
                            if isinstance(child, ttk.Frame) and child.winfo_width() > 200:
                                main_content = child
                                break
                 
                if main_content:
                    # Try to determine which view is open and refresh it
                    title_widget = None
                    for widget in main_content.winfo_children():
                        if isinstance(widget, ttk.Label) and widget.cget("text") in ["Dashboard Overview", "Accounts Management", "Transaction History"]:
                            title_widget = widget
                            break
                     
                    if title_widget:
                        if title_widget.cget("text") == "Dashboard Overview":
                            self.load_dashboard_content(main_content)
                        elif title_widget.cget("text") == "Accounts Management":
                            self.load_accounts_content(main_content)
                        elif title_widget.cget("text") == "Transaction History":
                            self.load_transactions_content(main_content)
        except ValueError:
            error_label.config(text="Please enter a valid amount")
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def show_transfer_dialog(self):
        """Show dialog to make a transfer between accounts"""
        dialog = tk.Toplevel(self.root)
        dialog.title("Transfer Funds")
        dialog.geometry("400x350")
        dialog.resizable(False, False)
        dialog.transient(self.root)
        dialog.grab_set()
         
        # Create form
        form_frame = ttk.Frame(dialog)
        form_frame.pack(padx=20, pady=20, fill=tk.BOTH, expand=True)
         
        # Fetch accounts
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT id, account_number, account_type, balance
        FROM accounts
        WHERE user_id = ? AND status = 'active'
        ''', (self.current_user['id'],))
         
        accounts = cursor.fetchall()
        conn.close()
         
        account_options = [f"{account[1]} ({account[2]}) - ${account[3]:.2f}" for account in accounts]
        account_ids = [account[0] for account in accounts]
         
        # From Account
        from_label = ttk.Label(form_frame, text="From Account:")
        from_label.grid(row=0, column=0, sticky=tk.W, pady=10)
         
        from_var = tk.StringVar()
        if account_options:
            from_var.set(account_options[0])
         
        from_dropdown = ttk.Combobox(form_frame, textvariable=from_var, values=account_options, state="readonly")
        from_dropdown.grid(row=0, column=1, sticky=tk.W, pady=10)
         
        # To Account
        to_label = ttk.Label(form_frame, text="To Account:")
        to_label.grid(row=1, column=0, sticky=tk.W, pady=10)
         
        to_var = tk.StringVar()
        if len(account_options) > 1:
            to_var.set(account_options[1])
        elif account_options:
            to_var.set(account_options[0])
         
        to_dropdown = ttk.Combobox(form_frame, textvariable=to_var, values=account_options, state="readonly")
        to_dropdown.grid(row=1, column=1, sticky=tk.W, pady=10)
         
        # Amount
        amount_label = ttk.Label(form_frame, text="Amount:")
        amount_label.grid(row=2, column=0, sticky=tk.W, pady=10)
         
        amount_entry = ttk.Entry(form_frame)
        amount_entry.grid(row=2, column=1, sticky=tk.W, pady=10)
         
        # Description
        desc_label = ttk.Label(form_frame, text="Description (Optional):")
        desc_label.grid(row=3, column=0, sticky=tk.W, pady=10)
         
        desc_entry = ttk.Entry(form_frame)
        desc_entry.grid(row=3, column=1, sticky=tk.W, pady=10)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color)
        error_label.grid(row=4, column=0, columnspan=2, sticky=tk.W, pady=10)
         
        # Buttons
        button_frame = ttk.Frame(form_frame)
        button_frame.grid(row=5, column=0, columnspan=2, pady=20)
         
        transfer_button = ttk.Button(
            button_frame,
            text="Transfer Funds",
            command=lambda: self.make_transfer(
                from_var.get(),
                to_var.get(),
                amount_entry.get(),
                desc_entry.get(),
                error_label,
                dialog,
                account_ids,
                account_options,
                accounts
            )
        )
        transfer_button.pack(side=tk.LEFT, padx=5)
         
        cancel_button = ttk.Button(button_frame, text="Cancel", command=dialog.destroy)
        cancel_button.pack(side=tk.LEFT, padx=5)
     
    def make_transfer(self, from_account, to_account, amount, description, error_label, dialog, account_ids, account_options, accounts):
        """Process a transfer between accounts"""
        try:
            # Validate amount
            amount = float(amount)
            if amount <= 0:
                error_label.config(text="Amount must be positive")
                return
             
            # Get account IDs and balances
            from_index = account_options.index(from_account)
            from_id = account_ids[from_index]
            from_balance = accounts[from_index][3]
             
            to_index = account_options.index(to_account)
            to_id = account_ids[to_index]
             
            # Check if accounts are different
            if from_id == to_id:
                error_label.config(text="Cannot transfer to the same account")
                return
             
            # Check if sufficient balance
            if amount > from_balance:
                error_label.config(text="Insufficient balance")
                return
             
            # Set default description if none provided
            if not description:
                description = "Transfer between accounts"
             
            # Generate reference number
            reference_number = f"TRF-{random.randint(1000000, 9999999)}"
             
            # Get current date
            transaction_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
             
            # Update database
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            # Add withdrawal transaction
            cursor.execute('''
            INSERT INTO transactions (account_id, transaction_type, amount, description, transaction_date, reference_number, status)
            VALUES (?, ?, ?, ?, ?, ?, ?)
            ''', (from_id, "Transfer (Out)", amount, description, transaction_date, reference_number, "completed"))
             
            # Add deposit transaction
            cursor.execute('''
            INSERT INTO transactions (account_id, transaction_type, amount, description, transaction_date, reference_number, status)
            VALUES (?, ?, ?, ?, ?, ?, ?)
            ''', (to_id, "Transfer (In)", amount, description, transaction_date, reference_number, "completed"))
             
            # Update account balances
            cursor.execute('''
            UPDATE accounts SET balance = balance - ? WHERE id = ?
            ''', (amount, from_id))
             
            cursor.execute('''
            UPDATE accounts SET balance = balance + ? WHERE id = ?
            ''', (amount, to_id))
             
            conn.commit()
            conn.close()
             
            messagebox.showinfo("Success", f"Transfer of ${amount:.2f} completed successfully!")
            dialog.destroy()
             
            # Refresh the relevant view if it's open
            if self.current_frame:
                main_content = None
                for widget in self.current_frame.winfo_children():
                    if isinstance(widget, ttk.Frame) and widget.winfo_children():
                        for child in widget.winfo_children():
                            if isinstance(child, ttk.Frame) and child.winfo_width() > 200:
                                main_content = child
                                break
                 
                if main_content:
                    # Try to determine which view is open and refresh it
                    title_widget = None
                    for widget in main_content.winfo_children():
                        if isinstance(widget, ttk.Label) and widget.cget("text") in ["Dashboard Overview", "Accounts Management", "Transaction History"]:
                            title_widget = widget
                            break
                     
                    if title_widget:
                        if title_widget.cget("text") == "Dashboard Overview":
                            self.load_dashboard_content(main_content)
                        elif title_widget.cget("text") == "Accounts Management":
                            self.load_accounts_content(main_content)
                        elif title_widget.cget("text") == "Transaction History":
                            self.load_transactions_content(main_content)
        except ValueError:
            error_label.config(text="Please enter a valid amount")
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def view_account_details(self, account_id):
        """Show detailed view of an account"""
        if not account_id:
            return
         
        # Fetch account details
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT * FROM accounts WHERE id = ?
        ''', (account_id,))
         
        account = cursor.fetchone()
         
        if not account:
            conn.close()
            return
         
        # Fetch recent transactions
        cursor.execute('''
        SELECT * FROM transactions
        WHERE account_id = ?
        ORDER BY transaction_date DESC
        LIMIT 10
        ''', (account_id,))
         
        transactions = cursor.fetchall()
        conn.close()
         
        # Create dialog
        dialog = tk.Toplevel(self.root)
        dialog.title(f"Account Details - {account[2]}")
        dialog.geometry("600x500")
        dialog.resizable(True, True)
        dialog.transient(self.root)
         
        # Account details section
        details_frame = ttk.Frame(dialog)
        details_frame.pack(fill=tk.X, padx=20, pady=20)
         
        # Account number
        number_label = ttk.Label(details_frame, text="Account Number:", font=("Helvetica", 10, "bold"))
        number_label.grid(row=0, column=0, sticky=tk.W, pady=5)
         
        number_value = ttk.Label(details_frame, text=account[2])
        number_value.grid(row=0, column=1, sticky=tk.W, pady=5)
         
        # Account type
        type_label = ttk.Label(details_frame, text="Account Type:", font=("Helvetica", 10, "bold"))
        type_label.grid(row=1, column=0, sticky=tk.W, pady=5)
         
        type_value = ttk.Label(details_frame, text=account[3])
        type_value.grid(row=1, column=1, sticky=tk.W, pady=5)
         
        # Balance
        balance_label = ttk.Label(details_frame, text="Current Balance:", font=("Helvetica", 10, "bold"))
        balance_label.grid(row=2, column=0, sticky=tk.W, pady=5)
         
        balance_value = ttk.Label(details_frame, text=f"${account[4]:.2f}")
        balance_value.grid(row=2, column=1, sticky=tk.W, pady=5)
         
        # Opening date
        opening_label = ttk.Label(details_frame, text="Opening Date:", font=("Helvetica", 10, "bold"))
        opening_label.grid(row=3, column=0, sticky=tk.W, pady=5)
         
        opening_value = ttk.Label(details_frame, text=account[5])
        opening_value.grid(row=3, column=1, sticky=tk.W, pady=5)
         
        # Status
        status_label = ttk.Label(details_frame, text="Status:", font=("Helvetica", 10, "bold"))
        status_label.grid(row=4, column=0, sticky=tk.W, pady=5)
         
        status_value = ttk.Label(details_frame, text=account[6].capitalize())
        status_value.grid(row=4, column=1, sticky=tk.W, pady=5)
         
        # Buttons
        button_frame = ttk.Frame(details_frame)
        button_frame.grid(row=5, column=0, columnspan=2, pady=10)
         
        deposit_button = ttk.Button(button_frame, text="Deposit", command=lambda: self.show_deposit_dialog(account_id))
        deposit_button.grid(row=0, column=0, padx=5)
         
        withdraw_button = ttk.Button(button_frame, text="Withdraw", command=lambda: self.show_withdraw_dialog(account_id))
        withdraw_button.grid(row=0, column=1, padx=5)
         
        # Transactions section
        transactions_label = ttk.Label(dialog, text="Recent Transactions", font=("Helvetica", 12, "bold"))
        transactions_label.pack(anchor=tk.W, padx=20, pady=(10, 5))
         
        # Create a treeview for transactions
        transactions_frame = ttk.Frame(dialog)
        transactions_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=10)
         
        columns = ("date", "type", "amount", "description", "reference", "status")
        tree = ttk.Treeview(transactions_frame, columns=columns, show="headings")
         
        # Define headings
        tree.heading("date", text="Date")
        tree.heading("type", text="Type")
        tree.heading("amount", text="Amount")
        tree.heading("description", text="Description")
        tree.heading("reference", text="Reference")
        tree.heading("status", text="Status")
         
        # Define columns
        tree.column("date", width=120)
        tree.column("type", width=100)
        tree.column("amount", width=80)
        tree.column("description", width=150)
        tree.column("reference", width=80)
        tree.column("status", width=80)
         
        # Add a scrollbar
        scrollbar = ttk.Scrollbar(transactions_frame, orient=tk.VERTICAL, command=tree.yview)
        tree.configure(yscroll=scrollbar.set)
        scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        tree.pack(fill=tk.BOTH, expand=True)
         
        # Populate the treeview with transactions
        for transaction in transactions:
            transaction_id = transaction[0]
            transaction_type = transaction[2]
            amount = transaction[3]
            description = transaction[4]
            transaction_date = transaction[5]
            reference = transaction[6]
            status = transaction[7]
             
            tree.insert("", tk.END, iid=transaction_id, values=(transaction_date, transaction_type, f"${amount:.2f}", description, reference, status))
     
    def view_transaction_details(self, transaction_id):
        """Show detailed view of a transaction"""
        if not transaction_id:
            return
         
        # Fetch transaction details
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute('''
        SELECT t.*, a.account_number, a.account_type
        FROM transactions t
        JOIN accounts a ON t.account_id = a.id
        WHERE t.id = ?
        ''', (transaction_id,))
         
        transaction = cursor.fetchone()
        conn.close()
         
        if not transaction:
            return
         
        # Create dialog
        dialog = tk.Toplevel(self.root)
        dialog.title(f"Transaction Details - {transaction[6]}")
        dialog.geometry("400x350")
        dialog.resizable(False, False)
        dialog.transient(self.root)
         
        # Transaction details section
        details_frame = ttk.Frame(dialog)
        details_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
         
        # Reference number
        ref_label = ttk.Label(details_frame, text="Reference Number:", font=("Helvetica", 10, "bold"))
        ref_label.grid(row=0, column=0, sticky=tk.W, pady=5)
         
        ref_value = ttk.Label(details_frame, text=transaction[6])
        ref_value.grid(row=0, column=1, sticky=tk.W, pady=5)
         
        # Account
        account_label = ttk.Label(details_frame, text="Account:", font=("Helvetica", 10, "bold"))
        account_label.grid(row=1, column=0, sticky=tk.W, pady=5)
         
        account_value = ttk.Label(details_frame, text=f"{transaction[8]} ({transaction[9]})")
        account_value.grid(row=1, column=1, sticky=tk.W, pady=5)
         
        # Type
        type_label = ttk.Label(details_frame, text="Transaction Type:", font=("Helvetica", 10, "bold"))
        type_label.grid(row=2, column=0, sticky=tk.W, pady=5)
         
        type_value = ttk.Label(details_frame, text=transaction[2])
        type_value.grid(row=2, column=1, sticky=tk.W, pady=5)
         
        # Amount
        amount_label = ttk.Label(details_frame, text="Amount:", font=("Helvetica", 10, "bold"))
        amount_label.grid(row=3, column=0, sticky=tk.W, pady=5)
         
        amount_value = ttk.Label(details_frame, text=f"${transaction[3]:.2f}")
        amount_value.grid(row=3, column=1, sticky=tk.W, pady=5)
         
        # Description
        desc_label = ttk.Label(details_frame, text="Description:", font=("Helvetica", 10, "bold"))
        desc_label.grid(row=4, column=0, sticky=tk.W, pady=5)
         
        desc_value = ttk.Label(details_frame, text=transaction[4] or "N/A")
        desc_value.grid(row=4, column=1, sticky=tk.W, pady=5)
         
        # Date
        date_label = ttk.Label(details_frame, text="Date:", font=("Helvetica", 10, "bold"))
        date_label.grid(row=5, column=0, sticky=tk.W, pady=5)
         
        date_value = ttk.Label(details_frame, text=transaction[5])
        date_value.grid(row=5, column=1, sticky=tk.W, pady=5)
         
        # Status
        status_label = ttk.Label(details_frame, text="Status:", font=("Helvetica", 10, "bold"))
        status_label.grid(row=6, column=0, sticky=tk.W, pady=5)
         
        status_value = ttk.Label(details_frame, text=transaction[7].capitalize())
        status_value.grid(row=6, column=1, sticky=tk.W, pady=5)
         
        # Close button
        close_button = ttk.Button(details_frame, text="Close", command=dialog.destroy)
        close_button.grid(row=7, column=0, columnspan=2, pady=20)
     
    def close_account(self, account_id):
        """Close an account"""
        if not account_id:
            return
         
        # Ask for confirmation
        if not messagebox.askyesno("Confirm", "Are you sure you want to close this account? This cannot be undone."):
            return
         
        # Check if account has balance
        conn = sqlite3.connect('bank_management.db')
        cursor = conn.cursor()
         
        cursor.execute("SELECT balance FROM accounts WHERE id = ?", (account_id,))
        balance = cursor.fetchone()[0]
         
        if balance > 0:
            if not messagebox.askyesno("Warning", f"This account has a balance of ${balance:.2f}. Do you want to proceed?"):
                conn.close()
                return
         
        # Update account status
        cursor.execute("UPDATE accounts SET status = 'closed' WHERE id = ?", (account_id,))
        conn.commit()
        conn.close()
         
        messagebox.showinfo("Success", "Account closed successfully")
         
        # Refresh the accounts view if it's open
        if self.current_frame:
            main_content = None
            for widget in self.current_frame.winfo_children():
                if isinstance(widget, ttk.Frame) and widget.winfo_children():
                    for child in widget.winfo_children():
                        if isinstance(child, ttk.Frame) and child.winfo_width() > 200:
                            main_content = child
                            break
             
            if main_content:
                title_widget = None
                for widget in main_content.winfo_children():
                    if isinstance(widget, ttk.Label) and widget.cget("text") == "Accounts Management":
                        title_widget = widget
                        break
                 
                if title_widget:
                    self.load_accounts_content(main_content)
     
    def show_edit_profile_dialog(self):
        """Show dialog to edit user profile"""
        dialog = tk.Toplevel(self.root)
        dialog.title("Edit Profile")
        dialog.geometry("400x400")
        dialog.resizable(False, False)
        dialog.transient(self.root)
        dialog.grab_set()
         
        # Create form
        form_frame = ttk.Frame(dialog)
        form_frame.pack(padx=20, pady=20, fill=tk.BOTH, expand=True)
         
        # Full Name
        name_label = ttk.Label(form_frame, text="Full Name:")
        name_label.grid(row=0, column=0, sticky=tk.W, pady=10)
         
        name_entry = ttk.Entry(form_frame, width=30)
        name_entry.grid(row=0, column=1, sticky=tk.W, pady=10)
        name_entry.insert(0, self.current_user['full_name'])
         
        # Email
        email_label = ttk.Label(form_frame, text="Email:")
        email_label.grid(row=1, column=0, sticky=tk.W, pady=10)
         
        email_entry = ttk.Entry(form_frame, width=30)
        email_entry.grid(row=1, column=1, sticky=tk.W, pady=10)
        email_entry.insert(0, self.current_user['email'])
         
        # Phone
        phone_label = ttk.Label(form_frame, text="Phone:")
        phone_label.grid(row=2, column=0, sticky=tk.W, pady=10)
         
        phone_entry = ttk.Entry(form_frame, width=30)
        phone_entry.grid(row=2, column=1, sticky=tk.W, pady=10)
        phone_entry.insert(0, self.current_user['phone'] or "")
         
        # Address
        address_label = ttk.Label(form_frame, text="Address:")
        address_label.grid(row=3, column=0, sticky=tk.W, pady=10)
         
        address_entry = ttk.Entry(form_frame, width=30)
        address_entry.grid(row=3, column=1, sticky=tk.W, pady=10)
        address_entry.insert(0, self.current_user['address'] or "")
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color)
        error_label.grid(row=4, column=0, columnspan=2, sticky=tk.W, pady=10)
         
        # Buttons
        button_frame = ttk.Frame(form_frame)
        button_frame.grid(row=5, column=0, columnspan=2, pady=20)
         
        save_button = ttk.Button(
            button_frame,
            text="Save Changes",
            command=lambda: self.update_profile(
                name_entry.get(),
                email_entry.get(),
                phone_entry.get(),
                address_entry.get(),
                error_label,
                dialog
            )
        )
        save_button.pack(side=tk.LEFT, padx=5)
         
        cancel_button = ttk.Button(button_frame, text="Cancel", command=dialog.destroy)
        cancel_button.pack(side=tk.LEFT, padx=5)
     
    def update_profile(self, full_name, email, phone, address, error_label, dialog):
        """Update user profile information"""
        try:
            # Validate fields
            if not full_name or not email:
                error_label.config(text="Full Name and Email are required")
                return
             
            # Update database
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            cursor.execute('''
            UPDATE users SET full_name = ?, email = ?, phone = ?, address = ?
            WHERE id = ?
            ''', (full_name, email, phone, address, self.current_user['id']))
             
            conn.commit()
            conn.close()
             
            # Update current user information
            self.current_user['full_name'] = full_name
            self.current_user['email'] = email
            self.current_user['phone'] = phone
            self.current_user['address'] = address
             
            messagebox.showinfo("Success", "Profile updated successfully")
            dialog.destroy()
             
            # Refresh the profile view if it's open
            if self.current_frame:
                main_content = None
                for widget in self.current_frame.winfo_children():
                    if isinstance(widget, ttk.Frame) and widget.winfo_children():
                        for child in widget.winfo_children():
                            if isinstance(child, ttk.Frame) and child.winfo_width() > 200:
                                main_content = child
                                break
                 
                if main_content:
                    title_widget = None
                    for widget in main_content.winfo_children():
                        if isinstance(widget, ttk.Label) and widget.cget("text") == "User Profile":
                            title_widget = widget
                            break
                     
                    if title_widget:
                        self.load_profile_content(main_content)
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def show_change_password_dialog(self):
        """Show dialog to change password"""
        dialog = tk.Toplevel(self.root)
        dialog.title("Change Password")
        dialog.geometry("400x300")
        dialog.resizable(False, False)
        dialog.transient(self.root)
        dialog.grab_set()
         
        # Create form
        form_frame = ttk.Frame(dialog)
        form_frame.pack(padx=20, pady=20, fill=tk.BOTH, expand=True)
         
        # Current Password
        current_label = ttk.Label(form_frame, text="Current Password:")
        current_label.grid(row=0, column=0, sticky=tk.W, pady=10)
         
        current_entry = ttk.Entry(form_frame, width=30, show="*")
        current_entry.grid(row=0, column=1, sticky=tk.W, pady=10)
         
        # New Password
        new_label = ttk.Label(form_frame, text="New Password:")
        new_label.grid(row=1, column=0, sticky=tk.W, pady=10)
         
        new_entry = ttk.Entry(form_frame, width=30, show="*")
        new_entry.grid(row=1, column=1, sticky=tk.W, pady=10)
         
        # Confirm New Password
        confirm_label = ttk.Label(form_frame, text="Confirm New Password:")
        confirm_label.grid(row=2, column=0, sticky=tk.W, pady=10)
         
        confirm_entry = ttk.Entry(form_frame, width=30, show="*")
        confirm_entry.grid(row=2, column=1, sticky=tk.W, pady=10)
         
        # Error message label
        error_label = ttk.Label(form_frame, text="", foreground=self.error_color)
        error_label.grid(row=3, column=0, columnspan=2, sticky=tk.W, pady=10)
         
        # Buttons
        button_frame = ttk.Frame(form_frame)
        button_frame.grid(row=4, column=0, columnspan=2, pady=20)
         
        save_button = ttk.Button(
            button_frame,
            text="Change Password",
            command=lambda: self.change_password(
                current_entry.get(),
                new_entry.get(),
                confirm_entry.get(),
                error_label,
                dialog
            )
        )
        save_button.pack(side=tk.LEFT, padx=5)
         
        cancel_button = ttk.Button(button_frame, text="Cancel", command=dialog.destroy)
        cancel_button.pack(side=tk.LEFT, padx=5)
     
    def change_password(self, current_password, new_password, confirm_password, error_label, dialog):
        """Change user password"""
        try:
            # Validate fields
            if not current_password or not new_password or not confirm_password:
                error_label.config(text="All fields are required")
                return
             
            if new_password != confirm_password:
                error_label.config(text="New passwords do not match")
                return
             
            if len(new_password) < 6:
                error_label.config(text="Password must be at least 6 characters")
                return
             
            # Hash passwords
            current_hashed = hashlib.sha256(current_password.encode()).hexdigest()
            new_hashed = hashlib.sha256(new_password.encode()).hexdigest()
             
            # Verify current password
            conn = sqlite3.connect('bank_management.db')
            cursor = conn.cursor()
             
            cursor.execute("SELECT password FROM users WHERE id = ?", (self.current_user['id'],))
            stored_password = cursor.fetchone()[0]
             
            if current_hashed != stored_password:
                error_label.config(text="Current password is incorrect")
                conn.close()
                return
             
            # Update password
            cursor.execute("UPDATE users SET password = ? WHERE id = ?", (new_hashed, self.current_user['id']))
            conn.commit()
            conn.close()
             
            messagebox.showinfo("Success", "Password changed successfully")
            dialog.destroy()
        except Exception as e:
            error_label.config(text=f"Error: {str(e)}")
     
    def logout(self):
        """Log out current user and return to login screen"""
        self.current_user = None
        self.show_login()
 
# Animation Classes
class FadeAnimation:
    """Provides fade in/out animations for widgets"""
     
    @staticmethod
    def fade_in(widget, duration=500, steps=20):
        """Fade in a widget from transparent to opaque"""
        alpha = 0.0
        step_time = duration / steps
         
        def update_alpha(current_alpha):
            current_alpha += 1.0 / steps
            if current_alpha <= 1.0:
                widget.attributes("-alpha", current_alpha)
                widget.after(int(step_time), lambda: update_alpha(current_alpha))
         
        widget.attributes("-alpha", alpha)
        update_alpha(alpha)
     
    @staticmethod
    def fade_out(widget, duration=500, steps=20, callback=None):
        """Fade out a widget from opaque to transparent"""
        alpha = 1.0
        step_time = duration / steps
         
        def update_alpha(current_alpha):
            current_alpha -= 1.0 / steps
            if current_alpha >= 0:
                widget.attributes("-alpha", current_alpha)
                widget.after(int(step_time), lambda: update_alpha(current_alpha))
            elif callback:
                callback()
         
        update_alpha(alpha)
 
class LoadingAnimation:
    """Provides a loading animation for long operations"""
     
    def __init__(self, parent, text="Loading..."):
        self.parent = parent
        self.text = text
        self.frame = None
        self.canvas = None
        self.angle = 0
        self.running = False
     
    def start(self):
        """Start the loading animation"""
        self.frame = ttk.Frame(self.parent)
        self.frame.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
         
        self.canvas = tk.Canvas(self.frame, width=100, height=100, bg=self.parent.cget("background"), highlightthickness=0)
        self.canvas.pack()
         
        self.text_id = self.canvas.create_text(50, 70, text=self.text, fill="#333333", font=("Helvetica", 10))
         
        self.running = True
        self.update_spinner()
     
    def update_spinner(self):
        """Update the spinner animation"""
        if not self.running:
            return
         
        self.canvas.delete("spinner")
         
        # Draw spinner
        x, y = 50, 40
        radius = 20
        segments = 8
        for i in range(segments):
            angle = self.angle + (i * 360 / segments)
            alpha = 0.2 + (i / segments) * 0.8
            color = self.get_color_with_alpha("#1a73e8", alpha)
             
            x1 = x + radius * cos(angle * 3.14159 / 180)
            y1 = y + radius * sin(angle * 3.14159 / 180)
            self.canvas.create_oval(x1-5, y1-5, x1+5, y1+5, fill=color, outline="", tags="spinner")
         
        self.angle = (self.angle + 10) % 360
        self.canvas.after(50, self.update_spinner)
     
    def get_color_with_alpha(self, color, alpha):
        """Convert color with alpha to hex format"""
        r = int(int(color[1:3], 16) * alpha + 255 * (1 - alpha))
        g = int(int(color[3:5], 16) * alpha + 255 * (1 - alpha))
        b = int(int(color[5:7], 16) * alpha + 255 * (1 - alpha))
        return f"#{r:02x}{g:02x}{b:02x}"
     
    def stop(self):
        """Stop the loading animation"""
        self.running = False
        if self.frame:
            self.frame.destroy()
            self.frame = None
 
# Main application launch
def main():
    root = tk.Tk()
    app = BankManagementSystem(root)
    root.mainloop()
 
if __name__ == "__main__":
    main()

To run the application:

  1. Make sure you have Python installed with tkinter and PIL (Pillow) libraries
  2. Copy the code to a .py file
  3. Run the file with Python
See also  Create Cab Booking System: Python Project

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

we provide projects, courses, and other stuff for free. in order for running we use Google ads to make revenue. please disable adblocker to support us.

Powered By
100% Free SEO Tools - Tool Kits PRO