Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from tkinter import *

"""
author : sujata5
Github Link : https://github.com/sujata5
"""

def click(event):
global scvalue
text = event.widget.cget("text")
print(text)
value = ""
if text=="=":
if scvalue.get().isdigit():
value = int(scvalue.get())
else:
try:
value = eval(screen.get())
except Exception as e:
print(e)
value = "Error"

elif text!="c":
value = scvalue.get()+ text

scvalue.set(value)
screen.update()

root = Tk()
root.geometry("600x900")
root.title("Calculator")
root.config(bg="orange")

scvalue = StringVar()
scvalue.set("")
screen = Entry(root, textvar=scvalue, font="lucida 30 bold")
screen.pack(fill=X, ipadx=8, pady=10, padx=10)


for i in range(9 ,0, -3):
f = Frame(root, bg="grey")

for i in range(i, i-3, -1):
b = Button(f, text=str(i), padx=10, pady=5, font="lucida 35 bold")
b.pack(side=LEFT, padx=10, pady=5)
b.bind("<Button-1>", click)

f.pack()


f = Frame(root, bg="grey")

for char in "0-*":
b = Button(f, text=char, padx=10, pady=5, font="lucida 35 bold")
b.pack(side=LEFT, padx=13, pady=5)
b.bind("<Button-1>", click)

f.pack()

f = Frame(root, bg="grey")

for char in "/%=":
b = Button(f, text=char, padx=10, pady=5, font="lucida 35 bold")
b.pack(side=LEFT, padx=9, pady=5)
b.bind("<Button-1>", click)

f.pack()

f = Frame(root, bg="grey")

b = Button(f, text="c", padx=10, pady=5, font="lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=5)
b.bind("<Button-1>", click)

b = Button(f, text="clac", padx=10, pady=5, font="lucida 25 bold")
b.pack(side=LEFT, padx=5, pady=5)


b = Button(f, text="+", padx=10, pady=5, font="lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=5)
b.bind("<Button-1>", click)
f.pack()


root.mainloop()