Build GUI Calculator using Python (Source Code @ Description) | Beginner Tutorial | Python World

Publicado em: 31 Dezembro 2020
no canal de: Python World
46
9

This Video is a Step-by-Step analysis on how to build a GUI Calculator Using Python.

Subscribe,Like And Share this video to everyone and jump to the next technology

Music by :NCS
Music Link :    • Julius Dreisig & Zeus X Crona - Invisible ...  

Source Code
from tkinter import *

def iCalc(source, side):
storeObj = Frame(source, borderwidth=4, bd=4, bg="powder blue")
storeObj.pack(side=side, expand =YES, fill =BOTH)
return storeObj

def button(source, side, text, command=None):
storeObj = Button(source, text=text, command=command)
storeObj.pack(side=side, expand = YES, fill=BOTH)
return storeObj

class app(Frame):
def __init__(self):
Frame.__init__(self)
self.option_add('*Font', 'arial 20 bold')
self.pack(expand = YES, fill =BOTH)
self.master.title('Calculator')

display = StringVar()
Entry(self, relief=RIDGE, textvariable=display,
justify='right'
, bd=30, bg="powder blue").pack(side=TOP,
expand=YES, fill=BOTH)

for clearButton in (["C"]):
erase = iCalc(self, TOP)
for ichar in clearButton:
button(erase, LEFT, ichar, lambda
storeObj=display, q=ichar: storeObj.set(''))

for numButton in ("789/", "456*", "123-", "0.+"):
FunctionNum = iCalc(self, TOP)
for iEquals in numButton:
button(FunctionNum, LEFT, iEquals, lambda
storeObj=display, q=iEquals: storeObj
.set(storeObj.get() + q))

EqualButton = iCalc(self, TOP)
for iEquals in "=":
if iEquals == '=':
btniEquals = button(EqualButton, LEFT, iEquals)
btniEquals.bind('(angled brackets)ButtonRelease-1(angled brackets)', lambda e,s=self,
storeObj=display: s.calc(storeObj), '+')


else:
btniEquals = button(EqualButton, LEFT, iEquals,
lambda storeObj=display, s=' %s ' % iEquals: storeObj.set
(storeObj.get() + s))

def calc(self, display):
try:
display.set(eval(display.get()))
except:
display.set("ERROR")


if __name__=='__main__':
app().mainloop()


Nesta página do site você pode assistir ao vídeo on-line Build GUI Calculator using Python (Source Code @ Description) | Beginner Tutorial | Python World duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Python World 31 Dezembro 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 46 vezes e gostou 9 espectadores. Boa visualização!