Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import ttk
- from tkinter import messagebox
- import math
- #Funciones
- def calcularSuma():
- global resultado
- numero1 = num1.get() # Se convierten las variables de Tkinter a variables de Python
- numero2 = num2.get()
- resultado = numero1 + numero2
- Label(pestañaSuma, text = "Total: %s" %(resultado)).grid(row=2, column=1)
- def calcularResta():
- global resultado
- numero1 = num1.get()
- numero2 = num2.get()
- resultado = numero1 - numero2
- Label(pestañaResta, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularMultipl():
- global resultado
- numero1 = num1.get()
- numero2 = num2.get()
- resultado = numero1 * numero2
- Label(pestañaMult, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularDivn():
- global resultado
- numero1 = num1.get()
- numero2 = num2.get()
- if numero2 == 0: # Evita que se pueda dividir por cero. La rasón por la cual uso un if, envez de un try es debido a que en Tkinter no me funcionaron :P
- # Label(pestañaDivn, text = "No se puede dividir por cero", fg = "#DC143C").place(x = 80, y = 200)
- messagebox.showwarning("Error!", "No se puede dividir por cero.")
- else:
- resultado = numero1 / numero2
- Label(pestañaDivn, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularRaizC():
- global resultado
- numero1 = num1.get()
- if numero1 >= 0:
- resultado = math.sqrt(numero1)
- Label(pestañaRaizC, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- else:
- messagebox.showwarning("Error!", "Solo se puede obtener valores arriba del 0")
- # Label(pestañaRaizC, text = "Solo se puede obtener valores arriba del 0", fg = "#DC143C").place(x = 80, y = 200)
- def calcularElevacn():
- global resultado
- numero1 = num1.get()
- numero2 = num2.get()
- resultado = math.pow(numero1, numero2)
- Label(pestañaElevacn, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularCos():
- global resultado
- numero1 = num1.get()
- resultado = math.cos(numero1)
- Label(pestañaCos, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularSin():
- global resultado
- numero1 = num1.get()
- resultado = math.sin(numero1)
- Label(pestañaSin, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularTan():
- global resultado
- numero1 = num1.get()
- resultado = math.tan(numero1)
- Label(pestañaTan, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def calcularArctan():
- global resultado
- numero1 = num1.get()
- resultado = math.atan(numero1)
- Label(pestañaArctan, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularArCos():
- global resultado
- numero1 = num1.get()
- resultado = math.acos(numero1)
- Label(pestañaArCos, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularArSin():
- global resultado
- numero1 = num1.get()
- resultado = math.asin(numero1)
- Label(pestañaArSin, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularSinh():
- global resultado
- numero1 = num1.get()
- resultado = math.sinh(numero1)
- Label(pestañaSinh, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularCosh():
- global resultado
- numero1 = num1.get()
- resultado = math.cosh(numero1)
- Label(pestañaCosh, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularTanh():
- global resultado
- numero1 = num1.get()
- resultado = math.tanh(numero1)
- Label(pestañaTanh, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularArCosh():
- global resultado
- numero1 = num1.get()
- resultado = math.acosh(numero1)
- Label(pestañaArCosh, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularArSinh():
- global resultado
- numero1 = num1.get()
- resultado = math.asinh(numero1)
- Label(pestañaArSinh, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularArTanh():
- global resultado
- numero1 = num1.get()
- resultado = math.atanh(numero1)
- Label(pestañaArTanh, text = "Total: %s" % (resultado)).place(x = 80, y = 200)
- def calcularLog():
- global resultado
- numero1 = num1.get()
- resultado = math.log(numero1)
- Label(pestañaLog, text = "Total: %s" %(resultado)).place(x = 80, y = 200)
- def put_in_num1():
- num1.set(resultado)
- def put_in_num2():
- num2.set(resultado)
- #Codigo Principal
- ventanaPrincipal = Tk()
- resultado = 0 # assign value at start
- num1 = DoubleVar() # Se declara variable para los numeros
- num2 = DoubleVar()
- ventanaPrincipal.geometry("800x600")
- ventanaPrincipal.title("Calculadora Cientifica")
- #ventanaPrincipal.iconbitmap('icon.ico') # Le pone un icono a la ventana
- notebook = ttk.Notebook(ventanaPrincipal) # Crea las pestañas
- notebook.pack(fill = 'both', expand = 'yes') # La pestaña se expande si no colisiona con ningun objeto
- pestañaSuma = ttk.Frame(notebook) # Crea la ventana
- pestañaResta = ttk.Frame(notebook)
- pestañaMult = ttk.Frame(notebook)
- pestañaDivn = ttk.Frame(notebook)
- pestañaRaizC = ttk.Frame(notebook)
- pestañaElevacn = ttk.Frame(notebook)
- pestañaCos = ttk.Frame(notebook)
- pestañaSin = ttk.Frame(notebook)
- pestañaTan = ttk.Frame(notebook)
- pestañaLog = ttk.Frame(notebook)
- pestañaArctan = ttk.Frame(notebook)
- pestañaSinh = ttk.Frame(notebook)
- pestañaCosh = ttk.Frame(notebook)
- pestañaTanh = ttk.Frame(notebook)
- pestañaArCosh = ttk.Frame(notebook)
- pestañaArSinh = ttk.Frame(notebook)
- pestañaArTanh = ttk.Frame(notebook)
- pestañaArCos = ttk.Frame(notebook)
- pestañaArSin = ttk.Frame(notebook)
- notebook.add(pestañaSuma, text = 'Suma') # Añade un titulo a la pestaña e inicializa la ventana
- notebook.add(pestañaResta, text = 'Resta')
- notebook.add(pestañaMult, text = 'Multiplicación')
- notebook.add(pestañaDivn, text = 'División')
- notebook.add(pestañaRaizC, text = 'Raíz Cuadrada')
- notebook.add(pestañaElevacn, text = 'Elevación')
- notebook.add(pestañaCos, text = 'Coseno')
- notebook.add(pestañaSin, text = 'Seno')
- notebook.add(pestañaTan, text = 'Tangente')
- notebook.add(pestañaLog, text = 'Logaritmo')
- notebook.add(pestañaArctan, text = 'Arctangente')
- notebook.add(pestañaArCos, text = 'Coseno inverso')
- notebook.add(pestañaArSin, text = 'Seno inverso')
- notebook.add(pestañaSinh, text = 'Sin hiperbolico')
- notebook.add(pestañaCosh, text = 'Cos hiperbolico')
- notebook.add(pestañaTanh, text = 'Tan hiperbolico')
- notebook.add(pestañaArCosh, text = 'Arcos hiperbolico')
- notebook.add(pestañaArSinh, text = 'Arsin hiperbolico')
- notebook.add(pestañaArTanh, text = 'Artang hiperbolico')
- ######################Pestaña 1 (Suma)######################
- Label(pestañaSuma, text = "Introduce un número").grid(row=0, column=0)
- Entry(pestañaSuma, textvariable = num1).grid(row=0, column=1)
- Button(pestañaSuma, text='<< Put "total" here', command=put_in_num1).grid(row=0, column=2)
- Label(pestañaSuma, text = "Introduce otro número").grid(row=1, column=0)
- Entry(pestañaSuma, textvariable = num2).grid(row=1, column=1)
- Button(pestañaSuma, text='<< Put "total" here', command=put_in_num2).grid(row=1, column=2)
- Button(pestañaSuma, text = "Obtener resultado", fg = "#228B22", command = calcularSuma).grid(row=2, column=0)
- ######################Pestaña 2 (Resta)######################
- Label(pestañaResta, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaResta, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaResta, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Label(pestañaResta, text = "Introduce otro número").place(x = 20, y = 80)
- Entry(pestañaResta, textvariable = num2).place(x = 200, y = 80)
- Button(pestañaResta, text='<< Put "total" here', command=put_in_num2).place(x=400, y=80)
- Button(pestañaResta, text = "Obtener resultado", fg = "#228B22", command = calcularResta).place(x = 100, y = 150)
- ######################Pestaña 3 (Multiplicación)######################
- Label(pestañaMult, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaMult, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaMult, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Label(pestañaMult, text = "Introduce otro número").place(x = 20, y = 80)
- Entry(pestañaMult, textvariable = num2).place(x = 200, y = 80)
- Button(pestañaMult, text = "Obtener resultado", fg = "#228B22", command = calcularMultipl).place(x = 100, y = 150)
- ######################Pestaña 4 (División)######################
- Label(pestañaDivn, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaDivn, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaDivn, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Label(pestañaDivn, text = "Introduce otro número").place(x = 20, y = 80)
- Entry(pestañaDivn, textvariable = num2).place(x = 200, y = 80)
- Button(pestañaDivn, text = "Obtener resultado", fg = "#228B22", command = calcularDivn).place(x = 100, y = 150)
- ######################Pestaña 5 (Raíz Cuadrada)#################
- Label(pestañaRaizC, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaRaizC, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaRaizC, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaRaizC, text = "Obtener resultado", fg = "#228B22", command = calcularRaizC).place(x = 100, y = 150)
- ######################Pestaña 6 (Elevación)######################
- Label(pestañaElevacn, text = "Introduce el numero a elevar").place(x = 20, y = 50)
- Entry(pestañaElevacn, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaElevacn, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Label(pestañaElevacn, text = "Introduce el exponente").place(x = 20, y = 80)
- Entry(pestañaElevacn, textvariable = num2).place(x = 200, y = 80)
- Button(pestañaElevacn, text = "Obtener resultado", fg = "#228B22", command = calcularElevacn).place(x = 100, y = 150)
- ######################Pestaña 7 (Coseno)#########################
- Label(pestañaCos, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaCos, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaCos, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaCos, text = "Obtener resultado", fg = "#228B22", command = calcularCos).place(x = 100, y = 150)
- ######################Pestaña 7 (Seno)###########################
- Label(pestañaSin, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaSin, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaSin, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaSin, text = "Obtener resultado", fg = "#228B22", command = calcularSin).place(x = 100, y = 150)
- ######################Pestaña 7 (Tangente)#######################
- Label(pestañaTan, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaTan, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaTan, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaTan, text = "Obtener resultado", fg = "#228B22", command = calcularTan).place(x = 100, y = 150)
- ######################Pestaña 7 (Logaritmo)######################
- Label(pestañaLog, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaLog, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaLog, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaLog, text = "Obtener resultado", fg = "#228B22", command = calcularLog).place(x = 100, y = 150)
- #################################################################
- Label(pestañaArctan, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaArctan, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaArctan, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaArctan, text = "Obtener resultado", fg = "#228B22", command = calcularArctan).place(x = 100, y = 150)
- ##################################################################
- Label(pestañaSinh, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaSinh, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaSinh, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaSinh, text = "Obtener resultado", fg = "#228B22", command = calcularSinh).place(x = 100, y = 150)
- ##################################################################
- Label(pestañaCosh, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaCosh, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaCosh, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaCosh, text = "Obtener resultado", fg = "#228B22", command = calcularCosh).place(x = 100, y = 150)
- ##################################################################
- Label(pestañaArSin, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaArSin, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaArSin, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaArSin, text = "Obtener resultado", fg = "#228B22", command = calcularArSin).place(x = 100, y = 150)
- ##################################################################
- Label(pestañaTanh, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaTanh, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaTanh, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaTanh, text = "Obtener resultado", fg = "#228B22", command = calcularTanh).place(x = 100, y = 150)
- ###################################################################
- Label(pestañaArCosh, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaArCosh, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaArCosh, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaArCosh, text = "Obtener resultado", fg = "#228B22", command = calcularArCosh).place(x = 100, y = 150)
- ###################################################################
- Label(pestañaArCos, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaArCos, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaArCos, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaArCos, text = "Obtener resultado", fg = "#228B22", command = calcularArCos).place(x = 100, y = 150)
- Label(pestañaArSinh, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaArSinh, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaArSinh, text = "Obtener resultado", fg = "#228B22", command = calcularArSinh).place(x = 100, y = 150)
- ###################################################################
- Label(pestañaArTanh, text = "Introduce un número").place(x = 20, y = 50)
- Entry(pestañaArTanh, textvariable = num1).place(x = 200, y = 50)
- Button(pestañaArTanh, text='<< Put "total" here', command=put_in_num1).place(x=400, y=50)
- Button(pestañaArTanh, text = "Obtener resultado", fg = "#228B22", command = calcularArTanh).place(x = 100, y = 150)
- ###################################################################
- mainloop() # Crea el mainloop para la ventana
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement