Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
from tkinter import* root = Tk() root.title("Primeira janela") frame = Frame(root) txt = Entry(frame) txt.grid(row=0, columnspan=4) def callback(texto): txt.insert(END, texto) def calcular(calculo): resultado = str(eval(txt.get())) txt.delete(0, END) txt.insert(END, resultado) def apagar(deletar): txt.delete(len(txt.get())-1,END) numero1 = Button(frame, text="1", command = lambda: callback("1")) numero1.grid(row=1, column=0, sticky=W+E+N+S) numero2 = Button(frame, text="2", command=lambda: callback("2")) numero2.grid(row=1, column=1, sticky=W+E+N+S) numero3 = Button(frame, text="3", command=lambda: callback("3")) numero3.grid(row=1, column=2, sticky=W+E+N+S) back= Button(frame, text="<-", command=lambda: apagar("<-")) back.grid(row=1, column=3, sticky=W+E+N+S) numero4 = Button(frame, text="4", command=lambda: callback("4")) numero4.grid(row=2, column=0, sticky=W+E+N+S) numero5 = Button(frame, text="5", command=lambda: callback("5")) numero5.grid(row=2, column=1, sticky=W+E+N+S) numero6 = Button(frame, text="6", command=lambda: callback("6")) numero6.grid(row=2, column=2, sticky=W+E+N+S) menos= Button(frame, text="-", command=lambda: callback("-")) menos.grid(row=2, column=3, sticky=W+E+N+S) numero7 = Button(frame, text="7", command=lambda: callback("7")) numero7.grid(row=3, column=0, sticky=W+E+N+S) numero8 = Button(frame, text="8", command=lambda: callback("8")) numero8.grid(row=3, column=1, sticky=W+E+N+S) numero9 = Button(frame, text="9", command=lambda: callback("9")) numero9.grid(row=3, column=2, sticky=W+E+N+S) multiplicação = Button(frame, text="*", command=lambda: callback("*")) multiplicação.grid(row=3, column=3, sticky=W+E+N+S) numero0 = Button(frame, text="0", command=lambda: callback("0")) numero0.grid(row=4, column=0, sticky=W+E+N+S) ponto = Button(frame, text=".", command=lambda: callback(".")) ponto.grid(row=4, column=1, sticky=W+E+N+S) divisão = Button(frame, text="/", command=lambda: callback("/")) divisão.grid(row=4, column=2, sticky=W+E+N+S) soma = Button(frame, text="+", command=lambda: callback("+")) soma.grid(row=4, column=3, sticky=W+E+N+S) iguladade = Button(frame, text="=", command=lambda: calcular("=")) iguladade.grid(row=5, columnspan=4, sticky=W+E+N+S) frame.pack() root.mainloop()
Compartilhar