├── Polling.py ├── README.md ├── main.db └── myelection.db /Polling.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | from tkinter import * 3 | from tkinter import ttk 4 | from tkinter import messagebox 5 | from tkinter import simpledialog 6 | from tkinter import filedialog as fd 7 | import sqlite3 as sqltor 8 | import matplotlib.pyplot as plt 9 | conn=sqltor.connect('main.db') #main database 10 | cursor=conn.cursor() #main cursor 11 | cursor.execute("""CREATE TABLE IF NOT EXISTS poll 12 | (name)""") 13 | 14 | def pollpage(): #page for polling 15 | def proceed(): 16 | chose=choose.get() 17 | print(chose) 18 | command='update polling set votes=votes+1 where name=?' 19 | pd.execute(command,(chose,)) 20 | pd.commit() 21 | messagebox.showinfo('Success!','You have voted') 22 | choose=StringVar() 23 | names=[] 24 | pd=sqltor.connect(plname+'.db') #poll database 25 | pcursor=pd.cursor() #poll cursor 26 | pcursor.execute('select name from polling') 27 | data=pcursor.fetchall() 28 | for i in range(len(data)): 29 | data1=data[i] 30 | ndata=data1[0] 31 | names.append(ndata) 32 | print(names) 33 | ppage=Toplevel() 34 | ppage.geometry('300x300') 35 | ppage.title('Poll') 36 | 37 | 38 | Label(ppage,text='Vote for any one person!').grid(row=1,column=3) 39 | for i in range(len(names)): 40 | Radiobutton(ppage,text=names[i],value=names[i],variable=choose).grid(row=2+i,column=1) 41 | Button(ppage,text='Vote',command=proceed).grid(row=2+i+1,column=2) 42 | 43 | 44 | def polls(): #mypolls 45 | def proceed(): 46 | global plname 47 | plname=psel.get() 48 | if plname=='-select-': 49 | return messagebox.showerror('Error','select poll') 50 | else: 51 | mpolls.destroy() 52 | pollpage() 53 | cursor.execute('select name from poll') 54 | data=cursor.fetchall() 55 | pollnames=['-select-'] 56 | for i in range(len(data)): 57 | data1=data[i] 58 | ndata=data1[0] 59 | pollnames.append(ndata) 60 | psel=StringVar() 61 | mpolls=Toplevel() 62 | mpolls.geometry('270x200') 63 | mpolls.title('Voting Program') 64 | Label(mpolls,text='Select Poll',font='Helvetica 12 bold').grid(row=1,column=3) 65 | select=ttk.Combobox(mpolls,values=pollnames,state='readonly',textvariable=psel) 66 | select.grid(row=2,column=3) 67 | select.current(0) 68 | Button(mpolls,text='Proceed',command=proceed).grid(row=2,column=4) 69 | 70 | 71 | 72 | def create(): 73 | def proceed(): 74 | global pcursor 75 | pname=name.get() #pollname 76 | can=cname.get() #candidatename 77 | if pname=='': 78 | return messagebox.showerror('Error','Enter poll name') 79 | elif can=='': 80 | return messagebox.showerror('Error','Enter candidates') 81 | else: 82 | candidates=can.split(',') #candidate list 83 | command='insert into poll (name) values (?);' 84 | cursor.execute(command,(pname,)) 85 | conn.commit() 86 | pd=sqltor.connect(pname+'.db') #poll database 87 | pcursor=pd.cursor() #poll cursor 88 | pcursor.execute("""CREATE TABLE IF NOT EXISTS polling 89 | (name TEXT,votes INTEGER)""") 90 | for i in range(len(candidates)): 91 | command='insert into polling (name,votes) values (?, ?)' 92 | data=(candidates[i],0) 93 | pcursor.execute(command,data) 94 | pd.commit() 95 | pd.close() 96 | messagebox.showinfo('Success!','Poll Created') 97 | cr.destroy() 98 | 99 | name=StringVar() 100 | cname=StringVar() 101 | cr=Toplevel() 102 | cr.geometry('500x400') 103 | cr.title('Create a new poll') 104 | Label(cr,text='Enter Details',font='Helvetica 12 bold').grid(row=1,column=2) 105 | Label(cr,text='Enter Poll name: ').grid(row=2,column=1) 106 | Entry(cr,width=30,textvariable=name).grid(row=2,column=2) #poll name 107 | Label(cr,text='(eg: captain elections)').place(x=354,y=25) 108 | Label(cr,text='Enter Candidates: ').grid(row=3,column=1) 109 | Entry(cr,width=45,textvariable=cname).grid(row=3,column=2) #candidate name 110 | Label(cr,text='Note: Enter the candidate names one by one by putting commas').grid(row=4,column=2) 111 | Label(cr,text='eg: candidate1,candate2,candidate3....').grid(row=5,column=2) 112 | Button(cr,text='Proceed',command=proceed).grid(row=6,column=2) 113 | def selpl(): #pollresults 114 | def results(): 115 | sel=sele.get() #selected option 116 | if sel=='-select-': 117 | return messagebox.showerror('Error','Select Poll') 118 | else: 119 | pl.destroy() 120 | def project(): 121 | names=[] 122 | votes=[] 123 | for i in range(len(r)): 124 | data=r[i] 125 | names.append(data[0]) 126 | votes.append(data[1]) 127 | plt.title('Poll Result') 128 | plt.pie(votes,labels=names,autopct='%1.1f%%',shadow=True,startangle=140) 129 | plt.axis('equal') 130 | plt.show() 131 | 132 | res=Toplevel() #result-page 133 | res.geometry('300x300') 134 | res.title('Results!') 135 | Label(res,text='Here is the Result!',font='Helvetica 12 bold').grid(row=1,column=2) 136 | con=sqltor.connect(sel+'.db') 137 | pcursor=con.cursor() 138 | pcursor.execute('select * from polling') 139 | r=pcursor.fetchall() #data-raw 140 | for i in range(len(r)): 141 | data=r[i] 142 | Label(res,text=data[0]+': '+str(data[1])+' votes').grid(row=2+i,column=1) 143 | Button(res,text='Project Results',command=project).grid(row=2+i+1,column=2) 144 | 145 | 146 | cursor.execute('select name from poll') 147 | data=cursor.fetchall() 148 | pollnames=['-select-'] 149 | for i in range(len(data)): 150 | data1=data[i] 151 | ndata=data1[0] 152 | pollnames.append(ndata) 153 | sele=StringVar() 154 | pl=Toplevel() 155 | pl.geometry('300x200') 156 | pl.title('Voting System') 157 | Label(pl,text='Select Poll',font='Helvetica 12 bold').grid(row=1,column=1) 158 | sel=ttk.Combobox(pl,values=pollnames,state='readonly',textvariable=sele) 159 | sel.grid(row=2,column=1) 160 | sel.current(0) 161 | Button(pl,text='Get Results',command=results).grid(row=2,column=2) 162 | def about(): 163 | messagebox.showinfo('About','Developed by Andrew') 164 | 165 | 166 | home=Tk() 167 | home.geometry('400x400') 168 | home.title('Voting Program') 169 | home['bg'] = '#49A' 170 | Label(home,text='voting program made in python',font='Helvetica 12 bold',bg='#49A').grid(row=1,column=2) 171 | Button(home,text='Create new Poll +',command=create).grid(row=3,column=2) 172 | Button(home,text='My Polls',command=polls).grid(row=4,column=2) 173 | Button(home,text='Poll Results',command=selpl).grid(row=5,column=2) 174 | Label(home,text='GitHub:https://github.com/andrew-geeks',bg='#49A').grid(row=6,column=2) 175 | Label(home,text='Instagram:https://www.instagram.com/_andrewgeeks/',bg='#49A').grid(row=7,column=2) 176 | Button(home,text='About',command=about).grid(row=1,column=3) 177 | home.mainloop() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tkinter-voting-system-python 2 | A Python tkinter project with sqlite. This Voting System helps to cast votes to candidates and view the poll results 3 | You can create polls, vote in them and view their results. We have used tkinter,sqlite & matplotlib library. You can also project the results in a pie-chart format. 4 | Sqlite is used to create databases and manage the data. 5 | Web version: 6 | 7 | When you create a new poll, a new database is created to store the casted votes. 8 | I have created a sample poll: 'myelection' which incudes 3 candidates 9 | 10 | # Releases 11 | Latest: v1.0 12 | 13 | # Updates 14 | Coming Soon 15 | 16 | # Libraries Used 17 | 1. Tkinter 18 | 2. Matplotlib 19 | 3. Sqlite3 20 | 21 | # Installation 22 | ``` 23 | pip install matplotlib 24 | ``` 25 | >Sqlite3 and Tkinter are already installed with your python IDE. 26 | -------------------------------------------------------------------------------- /main.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-geeks/tkinter-voting-system/99f4b4cac82136e0b4ee964da575c7381274794a/main.db -------------------------------------------------------------------------------- /myelection.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-geeks/tkinter-voting-system/99f4b4cac82136e0b4ee964da575c7381274794a/myelection.db --------------------------------------------------------------------------------