-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcast_vote.py
315 lines (210 loc) · 9.29 KB
/
cast_vote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import sqlite3
import tkinter as tk
from tkinter import *
import time
import numpy as np
import os
from PIL import Image # For face recognition we will the the LBPH Face Recognizer
from PIL import Image , ImageTk
from tkinter import messagebox as ms
root = tk.Tk()
#root.geometry('500x500')
#root.title("Login Form")
#------------------------------------------------------
root.configure(background="seashell2")
#root.geometry("1300x700")
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("Sentimental Analysis On Customer Review")
#------------------Frame----------------------
#Fulllname = tk.StringVar()
vote = tk.IntVar()
id = tk.IntVar()
# def login():
# ##### tkinter window ######
# print("log")
# from subprocess import call
# call(["python", "Login1.py"])
# #++++++++++++++++++++++++++++++++++++++++++++
# #####For background Image
image2 =Image.open('im3.jpg')
image2 =image2.resize((w,h), Image.ANTIALIAS)
background_image=ImageTk.PhotoImage(image2)
background_label = tk.Label(root, image=background_image)
background_label.image = background_image
background_label.place(x=0, y=0) #, relwidth=1, relheight=1)
# Python program to convert a list to string
# Function to convert
import functools
import operator
def convertTuple(tup):
str = functools.reduce(operator.add, (tup))
return str
# Driver code
# tuple = ('g', 'e', 'e', 'k', 's')
# str = convertTuple(tuple)
# print(str)
# # Driver code
# str = convertTuple(tuple)
# print(str)
def cast_vote():
#fname = Fulllname.get()
vote1 = vote.get()
f1 = open("id.txt","r")
id = f1.read()
print(id)
f1.close()
with sqlite3.connect('upload_cad.db') as db:
c = db.cursor()
# Find Existing username if any take proper action
find_user = ('SELECT * FROM cast_vote WHERE id = ?')
c.execute(find_user, [(id)])
# else:
# ms.showinfo('Success!', 'Account Created Successfully !')
# if (fname.() or (fname == "")):
# ms.showinfo("Message", "please enter valid name")
if (c.fetchall()):
ms.showerror('Error!', 'You Already Voted')
else:
conn = sqlite3.connect('upload_cad.db')
with conn:
cursor = conn.cursor()
cursor.execute('INSERT INTO cast_vote(id, vote) VALUES(?,?)',
(id, vote1))
if vote1 == 1:
find_user = ('SELECT Count FROM count WHERE Party = 1')
print(find_user)
c.execute(find_user)
s = c.fetchall()
print(s)
print(type(s))
a = s[0]
print(a)
#print(listToString(s))
str1 = convertTuple(a)
print(str1)
str2 = str1+1
print(str2)
# str2 = print(int(str2))
# conn = sqlite3.connect('upload_cad.db')
with conn:
cursor = conn.cursor()
cursor.execute("""UPDATE count SET Count= '{0}' WHERE Party = 1 """.format(str2))
conn.commit()
cursor.close()
db.close()
# elif vote1 == 2:
# find_user = ('SELECT Count FROM count WHERE Party = 1')
# print(find_user)
# c.execute(find_user)
# s = c.fetchall()
# print(s)
# print(type(s))
# a = s[0]
# print(a)
# #print(listToString(s))
# str1 = convertTuple(a)
# print(str1)
# str2 = str1+1
# print(str2)
# str2 = print(int(str2))
# conn = sqlite3.connect('upload_cad.db')
# with conn:
# cursor = conn.cursor()
# cursor.execute('INSERT INTO count (Count) VALUES(?)',(str2))
# conn.commit()
# conn.close()
# elif vote1 == 3:
# find_user = ('SELECT Count FROM count WHERE Party = 1')
# print(find_user)
# c.execute(find_user)
# s = c.fetchall()
# print(s)
# print(type(s))
# a = s[0]
# print(a)
# #print(listToString(s))
# str1 = convertTuple(a)
# print(str1)
# str2 = str1+1
# print(str2)
# str2 = print(int(str2))
# conn = sqlite3.connect('upload_cad.db')
# with conn:
# cursor = conn.cursor()
# cursor.execute('INSERT INTO count (Count) VALUES(?)',(str2))
# conn.commit()
# conn.close()
#count = count+1
# elif vote1 == 2:
# vote1 ++
conn.commit()
db.close()
ms.showinfo('Success!', 'Vote submit Successfully !')
# window.destroy()
lbl = tk.Label(root, text="Cast Vote", font=('times', 35,' bold '), height=1, width=30,bg="#C04000",fg="white")
lbl.place(x=300, y=5)
# framed = tk.LabelFrame(root, text=" --WELCOME-- ", width=500, height=250, bd=5, font=('times', 14, ' bold '),bg="pink")
# framed.grid(row=0, column=0, sticky='nw')
# framed.place(x=20, y=100)
#++++++++++++++++++++++++++++++++++++++++++++
# l7 = tk.Label(root, text="AAP :", width=12, font=("Times new roman", 15, "bold"), bg="snow")
# l7.place(x=130, y=350)
# l7 = tk.Label(root, text="BJP :", width=12, font=("Times new roman", 15, "bold"), bg="snow")
# l7.place(x=130, y=350)
# l7 = tk.Label(root, text="CONG :", width=12, font=("Times new roman", 15, "bold"), bg="snow")
# l7.place(x=130, y=350)
# l7 = tk.Label(root, text="NOTA :", width=12, font=("Times new roman", 15, "bold"), bg="snow")
# l7.place(x=130, y=350)
# l7 = tk.Label(root, text="SS :", width=12, font=("Times new roman", 15, "bold"), bg="snow")
# l7.place(x=130, y=350)
# # gender
image1 = Image.open(r'D:/new/Smart_Voting_System/img/aap.png')
image1 = image1.resize((100, 100), Image.ANTIALIAS)
image_lab1 = ImageTk.PhotoImage(image1)
img_lb = tk.Label(root, image=image_lab1)
img_lb.image = image_lab1
img_lb.place(x=450, y=120) # , relwidth=1, relheight=1)
tk.Radiobutton(root, text="AAP", padx=5, width=5, bg="snow", font=("bold", 15),variable=vote,value=1).place(x=650,y=150)
image2 = Image.open(r'D:/new/Smart_Voting_System/img/bjp.png')
image2 = image2.resize((100, 100), Image.ANTIALIAS)
image_lab2 = ImageTk.PhotoImage(image2)
img_lb1 = tk.Label(root, image=image_lab2)
img_lb1.image = image_lab2
img_lb1.place(x=450, y=250)
tk.Radiobutton(root, text="BJP", padx=5, width=4, bg="snow", font=("bold", 15),variable=vote,value=2).place(x=650, y=280)
image3 = Image.open(r'D:/new/Smart_Voting_System/img/cong.jpg')
image3 = image3.resize((100, 100), Image.ANTIALIAS)
image_lab3 = ImageTk.PhotoImage(image3)
img_lb2 = tk.Label(root, image=image_lab3)
img_lb2.image = image_lab2
img_lb2.place(x=450, y=380)
tk.Radiobutton(root, text="CONG", padx=5, width=5, bg="snow", font=("bold", 15),variable=vote,value=3).place(x=650,y=410)
# image2 = Image.open(r'E:/Smart_Voting_System/img/aap.png')
# image2 = image2.resize((100, 100), Image.ANTIALIAS)
# image_lab2 = ImageTk.PhotoImage(image2)
# img_lb1 = tk.Label(root, image=image_lab2)
# img_lb1.image = image_lab2
# img_lb1.place(x=450, y=250)
# tk.Radiobutton(root, text="NOTA", padx=5, width=4, bg="snow", font=("bold", 15), value=4).place(x=650, y=450)
# image2 = Image.open(r'E:/Smart_Voting_System/img/aap.png')
# image2 = image2.resize((100, 100), Image.ANTIALIAS)
# image_lab2 = ImageTk.PhotoImage(image2)
# img_lb1 = tk.Label(root, image=image_lab2)
# img_lb1.image = image_lab2
# img_lb1.place(x=450, y=250)
# tk.Radiobutton(root, text="SS", padx=5, width=5, bg="snow", font=("bold", 15), value=5).place(x=650,y=550)
# # tk.Radiobutton(root, text="BJP", padx=20, width=4, bg="snow", font=("bold", 15), value=2).place(
# # x=440, y=350)
# image2 = Image.open(r'E:/Smart_Voting_System/img/aap.png')
# image2 = image2.resize((100, 100), Image.ANTIALIAS)
# image_lab2 = ImageTk.PhotoImage(image2)
# img_lb1 = tk.Label(root, image=image_lab2)
# img_lb1.image = image_lab2
# img_lb1.place(x=450, y=250)
btn = tk.Button(root, text="Submit", bg="red",font=("",20),fg="white", command = cast_vote,width=9, height=1)
btn.place(x=500, y=550)
#####For background Image
# button1 = tk.Button(framed, text='Login Now',width=15,height=3,bg='dark blue',fg='white',command=login,font='bold').place(x=20,y=35)
# button1 = tk.Button(framed, text='Register',width=17,height=3,bg='dark blue',fg='white',command=reg,font='bold').place(x=250,y=35)
root.mainloop()