Advertisement
teslariu

cal

May 22nd, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """ Programa que implementa una calculadora gráfica rudimentaria"""
  5.  
  6. import tkinter as tk
  7.  
  8. #########  funciones  ################
  9.  
  10. def suma():
  11.     suma = float(caja1.get()) + float(caja2.get())
  12.     ingresa_texto.set(str(suma))
  13.    
  14. def resta():
  15.     resta = float(caja1.get()) - float(caja2.get())
  16.     ingresa_texto.set(str(resta))
  17.    
  18. def producto():
  19.     producto = float(caja1.get()) * float(caja2.get())
  20.     ingresa_texto.set(str(producto))
  21.    
  22. def cociente():
  23.     cociente = float(caja1.get()) / float(caja2.get())
  24.     ingresa_texto.set(str(cociente))
  25.    
  26.  
  27.  
  28.  
  29. #########  entorno gráfico #############
  30. ventana = tk.Tk()
  31. ventana.config(width=400, height=300, bg="khaki")
  32. ventana.title("Calculadora")
  33.  
  34. ingresa_texto =  tk.StringVar()   # el valor de esta variable se muestra en la pantalla
  35. ingresa_texto.set("0")  
  36.  
  37. ## campo primer termino ####
  38. caja1 = tk.Entry()
  39. caja1.place(x=20, y=20, width=50, height=25)
  40. etiqueta = tk.Label(text="Primer valor", bg="khaki")
  41. etiqueta.place(x=20, y=50)
  42.  
  43. ## campo segundo termino ####
  44. caja2 = tk.Entry()
  45. caja2.place(x=120, y=20, width=50, height=25)
  46. etiqueta = tk.Label(text="Segundo valor", bg="khaki")
  47. etiqueta.place(x=120, y=50)
  48.  
  49. ## campo pantalla ####
  50. pantalla = tk.Entry(
  51.                 font=['arial',12,'bold'],
  52.                 textvariable = ingresa_texto,
  53.                 justify = "right",
  54.                 state = tk.DISABLED  # bloquea el ingreso de datos
  55.                 )
  56.                
  57.                
  58. pantalla.place(x=220, y=20, width=150, height=25)
  59. etiqueta = tk.Label(text="Total", bg="khaki")
  60. etiqueta.place(x=220, y=50)
  61.  
  62. ######  botones ######################################
  63.  
  64. ### suma #######
  65. boton = tk.Button(text="SUMA", bg="lightblue", command=suma)
  66. boton.place(x=10, y=100, width=100, height=30)
  67.  
  68. ### resta #######
  69. boton = tk.Button(text="RESTA", bg="lightblue", command=resta)
  70. boton.place(x=130, y=100, width=100, height=30)
  71.  
  72.  
  73. ### producto #######
  74. boton = tk.Button(text="PRODUCTO", bg="lightblue", command=producto)
  75. boton.place(x=10, y=150, width=100, height=30)
  76.  
  77. ### cociente #######
  78. boton = tk.Button(text="COCIENTE", bg="lightblue", command=cociente)
  79. boton.place(x=130, y=150, width=100, height=30)
  80.  
  81.  
  82.  
  83. ventana.mainloop()
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement