Skip to content

Instantly share code, notes, and snippets.

@go4Mor4
Last active May 11, 2019 02:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save go4Mor4/29fc2fb6bbd227135f61153e7c922452 to your computer and use it in GitHub Desktop.
Save go4Mor4/29fc2fb6bbd227135f61153e7c922452 to your computer and use it in GitHub Desktop.
from tkinter import *
class Calculator():
def __init__(self, master=None, **kwargs):
master.title('CALCULATOR')
master.geometry('339x400')
display = StringVar()
view = Entry(self,highlightthickness= 0, relief=SUNKEN, textvariable=display, border=0, font=('Calibri', 24))
view.bind('<Return>', lambda e, s=self, w=display: s.calc(w))
view.place(x=0, y=6, width=254, height=36)
view.focus_set()
y,x= 42.5,0
for key in ('123', '456', '789', 'C0.', '()%'):
for char in key:
if char == 'C':
self.button(char, x, y, lambda w=display: w.set(''))
x += 85
else:
self.button(char, x, y, lambda w=display, c=char: w.set(w.get() + c))
x+= 85
x = 0
y += 37
x,y = 255,6
for char in '=+-*/':
if char == '=':
btn = self.button(char, x, y)
btn.bind('<ButtonRelease>', lambda e, s=self, w=display: s.calc(w))
else:
self.button(char, x, y, lambda w=display, s='%s' % char: w.set(w.get() + s))
y += 37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment