· 6 years ago · Aug 17, 2019, 03:36 PM
1#import
2from tkinter import *
3import sqlite3 as sqlite3
4
5#making the background
6
7window = Tk()
8window.title("Kids Progress")
9
10window.geometry('800x600+0+0')
11
12header = Label(window, text="Kids Progress Manager", font=("arial", 30, "bold"), fg="white").pack()
13
14#connecting with database
15kidbase = sqlite3.connect("kids_data.db")
16c = kidbase.cursor()
17
18#making the label for taking input
19
20L1 = Label(window, text = "Term:", font=("arial", 18)).place(x=10, y=100)
21L2 = Label(window, text = "Enter Kids ID:", font=("arial", 18)).place(x=10, y=150)
22L3 = Label(window, text = "Bangla Number:", font=("arial", 18)).place(x=10, y=200)
23L4 = Label(window, text = "English Number:", font=("arial", 18)).place(x=10, y=250)
24L5 = Label(window, text = "Math Number:", font=("arial", 18)).place(x=10, y=300)
25
26# Create a variable for each list
27Termone = StringVar(window)
28Termone.set('----')
29
30Termtwo = StringVar(window)
31Termtwo.set('----')
32
33ID = StringVar(window)
34Bangla = StringVar(window)
35English = StringVar(window)
36Math = StringVar(window)
37
38# Dictionary for dropdown list
39
40Termlist = {'First', 'Mid', 'Final'}
41
42TermQ = OptionMenu(window, Termone, *Termlist)
43TermQ.place(x=220, y=105)
44
45TermP = OptionMenu(window, Termtwo, *Termlist)
46TermP.place(x=220, y=500)
47
48# Entry for input in GUI
49
50ID = Entry(window, textvariable=ID)
51ID.place(x=220, y=155)
52
53Bangla = Entry(window, textvariable=Bangla)
54Bangla.place(x=220, y=205)
55
56English = Entry(window, textvariable=English)
57English.place(x=220, y=255)
58
59Math = Entry(window, textvariable=Math)
60Math.place(x=220, y=305)
61
62# get function to read the input
63
64def get():
65 print("You have submitted a record")
66
67 c.execute('CREATE TABLE IF NOT EXISTS ' +Termone.get() + ' (ID INT, Bangla INT, English INT, Math INT)')
68 c.execute('INSERT INTO ' + Termone.get()+ ' (ID, Bangla, English, Math) VALUE(?, ?, ?, ?)' , (ID.get(), Bangla.get(), English.get(), Math.get()))
69
70 kidbase.commit()
71
72 #Reset fields after submit
73 Termone.set('----')
74 ID.set('')
75 Bangla.set('')
76 English.set('')
77 Math.set('')
78
79#clear boxes after submit button is hit
80def clear():
81 Termone.set('----')
82 Termtwo.set('----')
83 ID.set('')
84 Bangla.set('')
85 English.set('')
86 Math.set('')
87
88 cursor.commit()
89
90def record():
91 c.execute('SELECT * FROM' + Termtwo.get())
92
93 frame = Frame(window)
94 frame.place(x=400, y=150)
95
96 Lb = Listbox(frame, height = 8, width = 25, font=('arial', 12))
97 Lb.pack(side=LEFT, fill = Y)
98
99 scroll = Scrollbar(frame, orient = VERTICAL) #set scrollbar to list box for when entries exceed size of list box
100 scroll.config(command = Lb.yview)
101 scroll.pack(side = RIGHT, fill= Y)
102 Lb.config(yscrollcommand = scroll.set)
103
104 Lb.insert(0, 'Bangla, English, Math') #first row in listbox
105
106 data = c.fetchall() # Gets the data from the table
107
108 for row in data:
109 Lb.insert(1,row) # Inserts record row by row in list box
110
111 L6 = Label(window, text = Termtwo.get() + ' ', font=("arial", 16)).place(x=400,y=100) # Title of list box, given which compound lift is chosen
112
113 L7 = Label(window, text = "They are ordered from most recent", font=("arial", 16)).place(x=400,y=350)
114
115 kidbase.commit()
116
117button_1 = Button(window, text="Submit", command=get)
118button_1.place(x=100,y=400)
119
120button_2 = Button(window, text="Clear", command=clear)
121button_2.place(x=10,y=400)
122
123button_3 = Button(window, text="Open DB", command=record)
124button_3.place(x=10,y=500)
125
126window.mainloop()