-
Notifications
You must be signed in to change notification settings - Fork 0
/
VotingPage.py
65 lines (46 loc) · 3.23 KB
/
VotingPage.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
import tkinter as tk
import socket
from tkinter import *
from PIL import ImageTk,Image
def voteCast(root,frame1,vote,client_socket):
for widget in frame1.winfo_children():
widget.destroy()
client_socket.send(vote.encode()) #4
message = client_socket.recv(1024) #Success message
print(message.decode()) #5
message = message.decode()
if(message=="Successful"):
Label(frame1, text="Vote Casted Successfully",bg="steel blue", font=('Helvetica', 18, 'bold')).grid(row = 1, column = 1)
else:
Label(frame1, text="Vote Cast Failed... \nTry again",bg="steel blue", font=('Helvetica', 18, 'bold')).grid(row = 1, column = 1)
client_socket.close()
def votingPg(root,frame1,client_socket):
root.title("Cast Vote")
for widget in frame1.winfo_children():
widget.destroy()
Label(frame1, text="Cast Vote",bg="steel blue" ,font=('Helvetica', 18, 'bold')).grid(row = 0, column = 1, rowspan=1)
Label(frame1, text="",bg="steel blue").grid(row = 1,column = 0)
vote = StringVar(frame1,"-1")
Radiobutton(frame1, text = "BJP\n\nNarendra Modi",bg="light steel blue", variable = vote, value = "bjp", indicator = 0, height = 4, width=15, command = lambda: voteCast(root,frame1,"bjp",client_socket)).grid(row = 2,column = 1)
bjpLogo = ImageTk.PhotoImage((Image.open("img/bjp.png")).resize((45,45),Image.ANTIALIAS))
bjpImg = Label(frame1, image=bjpLogo).grid(row = 2,column = 0)
Radiobutton(frame1, text = "Congress\n\nRahul Gandhi",bg="light steel blue", variable = vote, value = "cong", indicator = 0, height = 4, width=15, command = lambda: voteCast(root,frame1,"cong",client_socket)).grid(row = 3,column = 1)
congLogo = ImageTk.PhotoImage((Image.open("img/cong.png")).resize((45,45),Image.ANTIALIAS))
congImg = Label(frame1, image=congLogo).grid(row = 3,column = 0)
Radiobutton(frame1, text = "Aam Aadmi Party\n\nArvind Kejriwal",bg="light steel blue", variable = vote, value = "aap", indicator = 0, height = 4, width=15, command = lambda: voteCast(root,frame1,"aap",client_socket) ).grid(row = 4,column = 1)
aapLogo = ImageTk.PhotoImage((Image.open("img/aap.webp")).resize((45,45),Image.ANTIALIAS))
aapImg = Label(frame1, image=aapLogo).grid(row = 4,column = 0)
Radiobutton(frame1, text = "Shiv Sena\n\nUdhav Thakrey", bg="light steel blue",variable = vote, value = "ss", indicator = 0, height = 4, width=15, command = lambda: voteCast(root,frame1,"ss",client_socket)).grid(row = 5,column = 1)
ssLogo = ImageTk.PhotoImage((Image.open("img/ss.jpg")).resize((45,45),Image.ANTIALIAS))
ssImg = Label(frame1, image=ssLogo).grid(row = 5,column = 0)
Radiobutton(frame1, text = "\nCommunist Party \nof India ",bg="light steel blue", variable = vote, value = "cpi", indicator = 0, height = 4, width=15, command = lambda: voteCast(root,frame1,"cpi",client_socket)).grid(row = 6,column = 1)
notaLogo = ImageTk.PhotoImage((Image.open("img/cpi.png")).resize((45,45),Image.ANTIALIAS))
notaImg = Label(frame1, image=notaLogo).grid(row = 6,column = 0)
frame1.pack()
root.mainloop()
# if __name__ == "__main__":
# root = Tk()
# root.geometry('500x500')
# frame1 = Frame(root)
# client_socket='Fail'
# votingPg(root,frame1,client_socket)