0% found this document useful (0 votes)
12 views2 pages

HJA

cool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

HJA

cool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import math

def suma(a, b):


return a + b

def resta(a, b):


return a - b

def multiplicacion(a, b):


return a * b

def division(a, b):


if b != 0:
return a / b
else:
return "Error: División por cero"
def seno(x):
return math.sin(x)

def coseno(x):
return math.cos(x)

def tangente(x):
return math.tan(x)

def logaritmo(x):
return math.log(x)
import tkinter as tk

def click_boton(valor):
entrada.insert(tk.END, valor)

def calcular():
try:
resultado = eval(entrada.get())
entrada.delete(0, tk.END)
entrada.insert(tk.END, str(resultado))
except:
entrada.delete(0, tk.END)
entrada.insert(tk.END, "Error")

ventana = tk.Tk()
ventana.title("Calculadora Científica")

entrada = tk.Entry(ventana, width=40, borderwidth=5)


entrada.grid(row=0, column=0, columnspan=4)

botones = [
'7', '8', '9', '/', '4', '5', '6', '*',
'1', '2', '3', '-', '0', '.', '=', '+'
]

fila = 1
columna = 0
for boton in botones:
tk.Button(ventana, text=boton, padx=20, pady=20, command=lambda b=boton:
click_boton(b)).grid(row=fila, column=columna)
columna += 1
if columna == 4:
columna = 0
fila += 1

tk.Button(ventana, text='C', padx=20, pady=20, command=lambda: entrada.delete(0,


tk.END)).grid(row=fila, column=columna)
tk.Button(ventana, text='=', padx=20, pady=20, command=calcular).grid(row=fila,
column=columna+1)

ventana.mainloop()

You might also like