4
INDEX
[Link] CONTENT Pg. No
1 ABSTRACT 6
2 REQUIREMENTS 6
3 LEARNING OBJECTIVES 6
4 LEARNING OUTCOMES 6
PROCEDURE TO FOLLOW IN PYTHON
5 7
TO WORK WITH TKINTER
STEPS TO CREATE ELECTRICITY BILL
6 7
CALCULATOR
7 SOURCE CODE 8
8 OUTPUT 14
9 CONCLUSION 17
10 BIBLIOGRAPHY 17
5
ABSTRACT
The objective of our project entitled " Electricity Billing System" is to generate
electricity bill with all the charges. Manual system that is employed is extremely
laborious and quite inadequate. It only makes the process more difficult and harder.
The aim of our project is to develop a system that is meant to partially computerize the
work performed in the Electricity Board like generating monthly electricity bill, by
entering the consuming unit of energy and generate the bill details to be stored in the
database system for future transaction references.
REQUIREMENTS
Programming languages : Python
Operating System : Windows 10
Database : SQL
Software Requirement: SQL, Spyder
Hardware Requirement: PC/Laptop
Other:Tkinter package
LEARNING OBJECTIVES
1. To learn how to incorporate tkinter modules with python
2. To learn how to create applications using GUI (Graphical User Interface)
LEARNING OUTCOMES
1. We will be learning how to make our project with the help of python
programming language and GUI
2. As a result, the proposed system is designed to automate the calculation and
payment of electricity bills for user convenience. This project improves the user
experience and reduces manual work for employees.
6
PROCEDURE TO FOLLOW IN PYTHON TO WORK WITH TKINTER
Tkinter is one among the many packages used to create a variety of GUI (Graphical
User Interface) applications.
Installing tkinter gui package:
1. Open 'Anaconda PowerShell Prompt'
2. Enter "conda install -c anaconda tk"
3. Press Y, until installation is complete
4. Run test program below
import tkinter
tkinter._test()
STEPS TO CREATE ELECTRICITY BILL CALCULATOR
Create a basic Tkinter GUI Window.
Define a function that calculates the slab, price and generates the total bill value
For Electricity units consumed
Upto 100 units, bill is waived off
For units more than 100 but less than 500, billed at Rs. 3/unit
For units more than 500 but less than 800, billed at Rs. 5/unit
For units more than 800 but less than 1000, billed at Rs. 7/unit
For units more than 1000, billed at Rs. 10/unit
Create Labels and text objects to be displayed on Windows
Arrange objects in a tabular grid format
Execute and assign the values on window objects for display
7
SOURCE CODE
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from [Link] import display
import tkinter as tk
import pandas as pd
import os
import [Link]
#main window
root = Tk()
[Link]("525x425+75+75")
[Link](0,0)
[Link]("Electricity Calculator")
##Functions
#ClearEntry
def clrEnt():
[Link](bg="#9FE2BF")
[Link](0,[Link])
[Link](text="", bg="white")
[Link]()
#Tariff Calculation
def tarifCalc():
if [Link]()=="":
[Link](bg="#C70039")
8
[Link](0,[Link])
[Link](0,"Error: Enter Units Consumed")
inpEnt.focus_set()
return
if not [Link]().isnumeric():
[Link](bg="#e74c3c")
[Link](0,[Link])
[Link](0,"Error: Enter a numeric value")
inpEnt.focus_set()
return
units = int([Link]())
bAmt = 0
if units >= 0 and units <=100:
bAmt=0
if units > 100 and units <=500:
units = units - 100
bAmt = units * 3
if units > 500 and units <=800:
units = units - 500
bAmt = 1200 + (units * 5)
if units >= 800 and units <=1000:
units = units - 800
bAmt = 2700 + (units * 7)
if units > 1000:
units = units - 1000
9
bAmt = 4100 + (units * 10)
units = int([Link]())
bAmt = "{:.2f}".format(bAmt)
print(bAmt)
[Link](text="Bill Amount:" + str(bAmt), bg="#3498db")
addRecBtn= Button(mf, text="ADD RECORD", bg="#27ae60",
fg="WHITE", width=12, font=("Sans Serif", 12, "bold"),
command=lambda:dbOps(units, bAmt))
[Link](relx=0.5, rely=0.8, anchor=CENTER)
[Link]()
def OnEntry():
clrEnt()
def dbInit():
conn=[Link](host="localhost",user="root",password="dbad
min", database="projects24")
cursor = [Link]()
create_table_query = """ CREATE TABLE IF NOT EXISTS elec_bill (
sNo INT AUTO_INCREMENT PRIMARY KEY,
uni INT, amt float(7,2) NOT NULL ) """
[Link](create_table_query)
[Link]()
[Link]()
def dbOps(u,b):
conn=[Link]
(host="localhost",user="root",password="dbadmin", database="projects24")
cursor = [Link]()
10
[Link]("insert into elec_bill (uni, amt) values (%s, %s)", (
int(u),float(b) ))
[Link](text="Record Added", bg="#76d7c4")
[Link]()
[Link]()
def viewEnt():
conn=[Link]
(host="localhost",user="root",password="dbadmin", database="projects24")
cursor = [Link]()
[Link]('SELECT * FROM elec_bill')
res=[Link]()
print(res)
#New Child Window
vWin = [Link](root)
vtf=Frame(vWin, width=350, height=400, bg="#d1f2eb")
[Link](side=TOP,fill="both")
vExit = Button(vtf, text = "Exit", fg = "Black", bg = "Red", font=("Sans Serif",
10, "bold"),width=8, command = [Link])
[Link](relx=0.5, rely=0.1, anchor=CENTER)
trv = [Link](vtf, selectmode ='browse')
[Link](relx=0.5, rely=0.55, anchor=CENTER)
scroll_x=[Link](trv,orient=HORIZONTAL)
scroll_x.pack(side=BOTTOM,fill=X)
scroll_y=[Link](trv,orient=VERTICAL)
scroll_y.pack(side=RIGHT,fill=Y)
rCol=("sNo","uni","amt")
11
tree=[Link](trv, columns=rCol, show="headings",
xscrollcommand=scroll_x.set, yscrollcommand=scroll_y.set)
[Link]('sNo', text='S. No.')
[Link]('uni', text='Units Consumed')
[Link]('amt', text='Billed Amount')
[Link]('#1', width=50, stretch=NO)
[Link]('#2', width=100, stretch=NO)
[Link]('#3', width=100, stretch=NO)
[Link](side=TOP,fill="both")
for x in res:
[Link]("","end", values=x)
[Link]()
#TopFrame
tf=Frame(root, width=100, height=75, bg="#FF7F50")
[Link](side=TOP,fill="both")
#TopElements
titleLbl = Label(tf, font=('Sans Serif',25,'bold'),text="TNEB Bill
Calculator",fg="#FFBF00",bg="#FF7F50",anchor="center")
[Link](relx=0.5, rely=0.3, anchor=CENTER)
subTitleLbl = Label(tf, font=('Sans Serif',15),text="Domestic
Tariff",bg="#FF7F50",anchor='n')
[Link](relx=0.5, rely=0.7, anchor=CENTER)
#MiddleFrame
mf=Frame(root, width=525, height=250, bg="white", borderwidth=3,
relief=GROOVE)
[Link](side=TOP,padx= 5, pady=5)
#MiddleElements #disp
12
Lbl=Label(mf,font=('Sans
Serif',25,'bold'),text="Hello...",fg="#273746",bg="#9FE2BF",anchor="center")
[Link](relx=0.5, rely=0.3, anchor=CENTER)
inpEnt=Entry(mf,font=("SansSerif",
20),fg="#273746",bg="#9FE2BF",justify=CENTER, width=25)
[Link](relx=0.5, rely=0.2, anchor=CENTER)
[Link]("<Button-1>", lambda e:clrEnt()) #Key Focus Set
[Link](0, "Enter Units Consumed")
billLbl = Label(mf, font=('Sans Serif',20,'bold'),bg="white",fg="#DFFF00",
anchor="center")
[Link](relx=0.5, rely=0.4, anchor=CENTER)
calcBtn= Button(mf, text="CALCULATE", bg="PURPLE", fg="WHITE",
width=12, font=("Sans Serif", 12, "bold"), command=lambda:tarifCalc())
[Link](relx=0.3, rely=0.6, anchor=CENTER)
clrBtn= Button(mf, text="CLEAR", bg="ORANGE", fg="WHITE", width=12,
font=("Sans Serif", 12, "bold"), command=lambda:clrEnt())
[Link](relx=0.7, rely=0.6, anchor=CENTER)
#BottomFrame
bf=Frame(root, width=400, height=75, highlight thickness=10)
[Link](side=TOP)
#BottomElements
viewBtn = Button(bf, font=('Sans Serif',15,'bold'),text="VIEW", bg="#40E0D0",
fg="WHITE", command=viewEnt)
[Link](relx=0.3, rely=0.5, anchor=CENTER)
exitBtn = Button(bf, font=('Sans Serif',15,'bold'),text="EXIT", bg="RED",
fg="WHITE", command=[Link])
[Link](relx=0.7, rely=0.5, anchor=CENTER)
dbInit()
[Link]()
13
OUTPUT
HOMEPAGE
BILL CALCUALTION
14
RECORD ADDED TO THE DATABASE
DATABASE
15
ERROR MESSAGES
CASE 1 – When Units field is empty
CASE 2 – When string input is given in Units field.
16
PYTHON OUTPUT
CONCLUSION
The goal of this project reduces the amount of manual data entry and gives greater
efficiency. The User Interface of the project is very friendly and can be intuitively used
by anyone with ease and guides to rectify any errors in the project with much effort. It
also decreases the amount of time taken to write details and other module
BIBLIOGRAPHY
[Link]
[Link]
[Link]
[Link]
17