0% found this document useful (0 votes)
144 views14 pages

Final Paper - Muhali

This document provides instructions for a course design project to create a mini calculator application using Python GUI. The application will perform basic calculation functions like addition, subtraction, multiplication, and division when the user inputs two numbers and selects an operator. It will be built using the Tkinter module to create a graphical user interface that resembles a standard calculator. The project will be evaluated based on analysis, design and development, testing, and an oral examination. It must be completed between May 4th and June 8th, 2017.

Uploaded by

Em Shabirin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views14 pages

Final Paper - Muhali

This document provides instructions for a course design project to create a mini calculator application using Python GUI. The application will perform basic calculation functions like addition, subtraction, multiplication, and division when the user inputs two numbers and selects an operator. It will be built using the Tkinter module to create a graphical user interface that resembles a standard calculator. The project will be evaluated based on analysis, design and development, testing, and an oral examination. It must be completed between May 4th and June 8th, 2017.

Uploaded by

Em Shabirin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

()

School Computer Science Major Software Engineering


Class 2016 IT Name Shabirin

.Course Design(Paper)Title Mini Calculator Using Python GUI


.Course Design(Paper)Start form 4th May 2017 to 8th June 2017
.Course Design(Paper) Address: Nanjing Xiaozhuang University
.Course Design(Paper) Specifications

1The Aim of the Course Design


The aim of this paper is to teach us some of the higher-level techniques that are
currently not covered in other computer graphics course, but are necessary to
implement interesting computer application. It is also to train our motor skills and helps
us in determining decisions and solve the problems and achieve the goal as soon as
possible. The second aim of the python programming is to get students familiar with
python to build a programming application. To this end, the course will have a heavy
programming focus.
2The Requirements of the Course Design
1Basic Requirements
With Python knowledge write a program to solve the problem.
An application that has a function to calculate two number, the first number and the
second number. Its depend on what function that we want to do. There are add, minus,
multiply, divide, and equal. It will show us the result of the operation.
2Other Requirements
Use python GUI with Tkinter Module
Application is built by the python GUI, so it will show the special interface as calculator
usual. It will use Tkinter module and the other component of it, such as button, entry,
label, listbox, and frame. To set the layout we use grid structure.
3The Requirements of the Paper
1The paper should includes: source code system study screen shot
2Write and print the paper according to the format.
1
4Assessment Details
1Analysis20 marks
2Design & Development50 marks
3Test10 marks
4Oral Examination20 marks
5References
[1] Hetland, Magnus Lie. Beginning Python from Novice to Professional, Second
Edition. New York: Apress and Springer-Verlag Inc, 2008.

[2] Severance, Charles. Python for Informatics: Exploring Information.


http://www.thinkpython.com, 2009

[3] http://courses.washington.edu/css450/2010.Fall/InterestingFinalProjects.html

6The Daily Schedule


Tasks Days Address
Research and Analysis 2 Lab 4th floor Heqin Lou
Design and Test 1 Lab 4th floor Heqin Lou
Write Paper 2 Home

Student Signature______
16 th June 2017

2
()

1Analysis20 marksExcellent ( ) , Good ( ), Satisfactory ( ),


Unsatisfactory ( ), Poor ( )
2Design & Development20 marksExcellent ( ) , Good ( ),
Satisfactory ( ), Unsatisfactory ( ), Poor ( )
3Test 20 marksExcellent ( ) , Good ( ), Satisfactory ( ),
Unsatisfactory ( ), Poor ( )
4Translation 20 marksExcellent ( ) , Good ( ), Satisfactory
( ), Unsatisfactory ( ), Poor ( )
5Oral Examination 20 marksExcellent ( ) , Good ( ),
Satisfactory ( ), Unsatisfactory ( ), Poor ( )
6Whether reduce to a lower rank because of the attendance or papers
format Yes ( ), No ( )
7Marks Excellent ( ) , Good ( ), Satisfactory ( ), Unsatisfactory ( ),
Poor ( )

Teacher Signature_____
16 th June 2017

3
Content
() ....................................................1

Content ............................................................................4

Demand analysis ........................................................................... 5

Source code ................................................................................... 6

References ...................................................................................13

4
This application is same as like a calculator application in the phone or
computer application. But, in this case we will build this application using python
programming. This application is mainly used for computer Windows XP or above
version of the use of user, this curriculum design is generally the realization of Mini
calculator of python. The application consists of some function that can calculate two
number, the first number and the second number. Its depend on what function that we
want to do. There are add, minus, multiply, divide, and equal. It will show us the result
of the operation.
This application built use python GUI with Tkinter Module. So, it will show the
special interface as calculator usual. It will use Tkinter module and the other component
of it, such as button, entry, label, listbox, and frame. To set the layout we use grid
structure. The goal is to have a result of the calculate operation.

5
# Mini Calculator Using Python GUI
# Calculator.py

# to import module
from Tkinter import *

# define the first variable


bil1 = "0"
bil2 = "0"
operator = "nihil"
hasil = "kosong"
# method for input.

def points():
global bil1
global bil2
getv = masukan.get()
if "." not in getv:
masukan.delete(0, END)
masukan.insert(0, getv + ".")
if getv == bil1:
bil1 = getv + "."
else:
bil2 = getv + "."

def input_field(x):
global bil1
global bil2
global operator
global hasil
if operator == "nihil" and hasil == "kosong":
get_value = masukan.get()
masukan.delete(0, END)
masukan.insert(0, get_value + x)
6
bil1 = get_value + x
elif operator != "nihil" and hasil == "kosong":
get_value = masukan.get()
if get_value == bil1:
masukan.delete(0, END)
masukan.insert(0, x)
bil2 = x
else:
masukan.delete(0, END)
masukan.insert(0, get_value + x)
bil2 = get_value + x
elif operator == "nihil" and hasil != "kosong" and bil1 != "0":
getv = masukan.get()
if "." in getv:
masukan.delete(0, END)
masukan.insert(0, getv + x)
bil1 = getv + x
else:
masukan.delete(0, END)
masukan.insert(0, x)
bil1 = x
hasil = "kosong"
elif operator != "nihil" and hasil != "kosong":
g = masukan.get()
if g == bil1:
masukan.delete(0, END)
masukan.insert(0, x)
bil2 = x
else:
masukan.delete(0, END)
masukan.insert(0, g + x)
bil2 = g + x

def clear():
global bil1
global bil2
global operator
global hasil
7
masukan.delete(0, END)
bil1 = "0"
bil2 = "0"
operator = "nihil"
hasil = "kosong"

def set_operator(x):
global operator

if operator == "nihil":
operator = x
else:
eksekusi()
operator = x

def eksekusi():
global bil1
global bil2
global operator
global hasil
if operator != "nihil":
if operator == "/" and bil2 == "0":
masukan.delete(0, END)
masukan.insert(0, "Error!")
hasilnya = "susah"
bil1 = hasilnya
else:
exec ("hasilnya = %s %s %s" % (bil1, operator, bil2))
masukan.delete(0, END)
masukan.insert(0, hasilnya)
bil1 = "%i" % hasilnya
else:
hasilnya = bil1
bil1 = hasilnya
bil2 = "0"
operator = "nihil"

8
def bilbul():
global bil1
global bil2
global opertor
getv = masukan.get()
if getv == bil1:
masukan.delete(0, END)
exec ("res = %s * -1" % getv)
masukan.insert(0, res)
bil1 = "%i" % res
else:
masukan.delete(0, END)
exec ("res = %s * -1" % getv)
masukan.insert(0, res)
bil2 = "%i" % res

root = Tk()
root.title("Mini Calculator Using Python") # give the title of the
frame application

# to define each component


masukan = Entry(width=20, font=("verdana", 20), justify="right") #
make a text field
satu = Button(text="1", width=5, font=("verdana", 13, "bold"),
command=lambda x="1": input_field(x)) # make button for
number 1
dua = Button(text="2", width=5, font=("verdana", 13, "bold"),
command=lambda x="2": input_field(x)) # make button for
number 2
tiga = Button(text="3", width=5, font=("verdana", 13, "bold"),
command=lambda x="3": input_field(x)) # make button for
number 3
clear = Button(text="C", width=11, font=("verdana", 13, "bold"),
command=clear) # make button for clear
empat = Button(text="4", width=5, font=("verdana", 13, "bold"),
command=lambda x="4": input_field(x)) # make button for
number 4
9
lima = Button(text="5", width=5, font=("verdana", 13, "bold"),
command=lambda x="5": input_field(x)) # make button for
number 5
enam = Button(text="6", width=5, font=("verdana", 13, "bold"),
command=lambda x="6": input_field(x)) # make button for
number 6
plus = Button(text="+", width=5, font=("verdana", 13, "bold"),
command=lambda x="+": set_operator(x)) # make button for
plus
tujuh = Button(text="7", width=5, font=("verdana", 13, "bold"),
command=lambda x="7": input_field(x)) # make button for
number 7
delapan = Button(text="8", width=5, font=("verdana", 13, "bold"),
command=lambda x="8": input_field(x)) # make button
for number 8
sembilan = Button(text="9", width=5, font=("verdana", 13, "bold"),
command=lambda x="9": input_field(x)) # make button
for number 9
minus = Button(text="-", width=5, font=("verdana", 13, "bold"),
command=lambda x="-": set_operator(x)) # make button
for minus
plusminus = Button(text="-/+", width=5, font=("verdana", 13, "bold"),
command=bilbul) # make button for -/+
nol = Button(text="0", width=5, font=("verdana", 13, "bold"),
command=lambda x="0": input_field(x)) # make button for number 0
point = Button(text=".", width=5, font=("verdana", 13, "bold"),
command=points) # make button for point
kali = Button(text="x", width=5, font=("verdana", 13, "bold"),
command=lambda x="*": set_operator(x)) # make button for
multiply
bagi = Button(text="/", width=5, font=("verdana", 13, "bold"),
command=lambda x="/": set_operator(x)) # make button for
devide
samadengan = Button(text="=", width=5, height=3, font=("verdana", 13,
"bold"), command=eksekusi)

# to set the layout of the calculator component


masukan.grid(column=0, row=0, columnspan=5)
satu.grid(column=0, row=1)
10
dua.grid(column=1, row=1)
tiga.grid(column=2, row=1)
clear.grid(column=3, row=1, columnspan=2)
empat.grid(column=0, row=2)
lima.grid(row=2, column=1)
enam.grid(column=2, row=2)
plus.grid(row=2, column=3)
tujuh.grid(row=3, column=0)
delapan.grid(row=3, column=1)
sembilan.grid(row=3, column=2)
minus.grid(row=3, column=3)
plusminus.grid(row=4, column=0)
nol.grid(row=4, column=1)
point.grid(row=4, column=2)
kali.grid(row=4, column=3)
bagi.grid(row=2, column=4)
samadengan.grid(row=3, column=4, rowspan=2)

mainloop()

11
The application consists of some function that can calculate two number, the
first number and the second number. Its depend on what function that we want to do.
There are add, minus, multiply, divide, and equal. It will show us the result of the
operation.

We have number 0 until 9, the button for add, minus, multiply, devide, and the equal. We
also have the point button, minus/plus number button and also the clear button to recalculate
the number. In the top of the application we have text field that can use to show the number
tha we click and also show the result of the opertation.

12
13
References

[1] Hetland, Magnus Lie. Beginning Python from Novice to Professional, Second
Edition. New York: Apress and Springer-Verlag Inc, 2008.

[2] Severance, Charles. Python for Informatics: Exploring Information.


http://www.thinkpython.com, 2009

[3] http://courses.washington.edu/css450/2010.Fall/InterestingFinalProjects.html

14

You might also like