text: import tkinter as tk
  from tkinter import messagebox
  
  # função dos botões
  def tela(elemento):
      if elemento not in '+-*/.':
          resultado.insert(tk.END, elemento)
  
      elif elemento in '+-*/.' and not resultado.get().endswith('+') and not resultado.get().endswith('-') and not resultado.get().endswith('*') and not resultado.get().endswith('/') and not resultado.get().endswith('.') and not resultado.get() == '':
          if elemento == '.':
              ultimo_op = 0
              for n in resultado.get():
                  if n in '+-*/':
                      ultimo_op = resultado.get().index(n)
              if resultado.get().count('.', ultimo_op, -1) == 0:
                  resultado.insert(tk.END, elemento)
          else:
              resultado.insert(tk.END, elemento)
  
  def btn_igual():
      if not resultado.get().endswith('+') and not resultado.get().endswith('-') and not resultado.get().endswith('*') and not resultado.get().endswith('/'):
          str_tela.set(str(eval(resultado.get())))
  
  # botões
  janela = tk.Tk()
  janela.title('Calculadora')
  janela.config(bg="grey")
  
  str_tela = tk.StringVar()
  resultado = tk.Entry(janela, textvariable=str_tela, bg="white", font=15, width=21, relief="sunken", justify=tk.RIGHT)
  resultado.grid(column=0, row=0, columnspan=5, padx=2, pady=2, ipady=8)
  
  b7 = tk.Button(janela, text='7', bg="white", font=15, height=2, width=3, command=lambda:tela('7'))
  b7.grid(column=0, row=1, padx=2, pady=2)
  
  b8 = tk.Button(janela, text='8', bg="white", font=15, height=2, width=3, command=lambda:tela('8'))
  b8.grid(column=1, row=1, padx=2, pady=2)
  
  b9 = tk.Button(janela, text='9', bg="white", font=15, height=2, width=3, command=lambda:tela('9'))
  b9.grid(column=2, row=1, padx=2, pady=2)
  
  b_mais = tk.Button(janela, text='+', bg="light blue", font=15, height=2, width=3, command=lambda:tela('+'))
  b_mais.grid(column=3, row=1, padx=2, pady=2)
  
  b4 = tk.Button(janela, text='4', bg="white", font=15, height=2, width=3, command=lambda:tela('4'))
  b4.grid(column=0, row=2, padx=2, pady=2)
  
  b5 = tk.Button(janela, text='5', bg="white", font=15, height=2, width=3, command=lambda:tela('5'))
  b5.grid(column=1, row=2, padx=2, pady=2)
  
  b6 = tk.Button(janela, text='6', bg="white", font=15, height=2, width=3, command=lambda:tela('6'))
  b6.grid(column=2, row=2, padx=2, pady=2)
  
  b_menos = tk.Button(janela, text='-', bg="light blue", font=15, height=2, width=3, command=lambda:tela('-'))
  b_menos.grid(column=3, row=2, padx=2, pady=2)
  
  b1 = tk.Button(janela, text='1', bg="white", font=15, height=2, width=3, command=lambda:tela('1'))
  b1.grid(column=0, row=3, padx=2, pady=2)
  
  b2 = tk.Button(janela, text='2', bg="white", font=15, height=2, width=3, command=lambda:tela('2'))
  b2.grid(column=1, row=3, padx=2, pady=2)
  
  b3 = tk.Button(janela, text='3', bg="white", font=15, height=2, width=3, command=lambda:tela('3'))
  b3.grid(column=2, row=3, padx=2, pady=2)
  
  b_mult = tk.Button(janela, text='x', bg="light blue", font=15, height=2, width=3, command=lambda:tela('*'))
  b_mult.grid(column=3, row=3, padx=2, pady=2)
  
  b0 = tk.Button(janela, text='0', bg="white", font=15, height=2, width=7, command=lambda:tela('0'))
  b0.grid(column=0, row=4, columnspan=2, padx=2, pady=2)
  
  b_virgula = tk.Button(janela, text='.', bg="white", font=15, height=2, width=3, command=lambda:tela('.'))
  b_virgula.grid(column=2, row=4, padx=2, pady=2)
  
  b_div = tk.Button(janela, text='/', bg="light blue", font=15, height=2, width=3, command=lambda:tela('/'))
  b_div.grid(column=3, row=4, padx=2, pady=2)
  
  b_igual = tk.Button(janela, text='=', bg="yellow", font=15, height=5, width=3, command=btn_igual)
  b_igual.grid(column=4, row=3, rowspan=2, padx=2, pady=2)
  
  b_apagar = tk.Button(janela, text='C', bg="red", font=15, height=2, width=3, command=lambda:str_tela.set(''))
  b_apagar.grid(column=4, row=1, padx=2, pady=2)
  
  b_apagar = tk.Button(janela, text='del', bg="red",font=15,  height=2, width=3, command=lambda:str_tela.set(resultado.get()[:-1]))
  b_apagar.grid(column=4, row=2, padx=2, pady=2)
  
  janela.mainloop()