Advertisement
teslariu

cal

Aug 14th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk
  5. from tkinter import ttk
  6.  
  7. def sumar_numeros():
  8.     x = float(a.get())
  9.     y = float(b.get())
  10.     suma = x + y
  11.     print(suma)
  12.     resultado.set(str(suma))
  13.    
  14.     # borro las cajas
  15.     a.delete(0,tk.END)
  16.     b.delete(0,tk.END)
  17.    
  18.    
  19.  
  20. ###################  ventana  #######################################
  21.  
  22.  
  23. ventana = tk.Tk()
  24.  
  25. resultado = tk.StringVar()
  26. resultado.set("0")
  27.  
  28. ventana.title("SUMADOR")
  29. ventana.config(width=600, height=300)
  30. ventana.resizable(0,0)
  31.  
  32. # campo primer sumando
  33. a = ttk.Entry()
  34. a.place(x=40, y=10)
  35. etiqueta = tk.Label(text="1º sumando")
  36. etiqueta.place(x=40, y=40)
  37.  
  38. # campo segundo sumando
  39. b = ttk.Entry()
  40. b.place(x=200, y=10)
  41. etiqueta = tk.Label(text="2º sumando")
  42. etiqueta.place(x=200, y=40)
  43.  
  44. # campo resultado
  45. total = tk.Entry(
  46.                 font=('arial',20,'bold'),
  47.                 state = tk.DISABLED,
  48.                 textvariable = resultado,
  49.                 bg = "lime green",
  50.                 justify = 'right'
  51.         )
  52.  
  53. total.place(x=100, y=90)
  54. etiqueta = tk.Label(text="Total")
  55. etiqueta.place(x=100, y=150)
  56.  
  57. boton = ttk.Button(text="SUMAR", command=sumar_numeros)
  58. boton.place(x=100, y=200)
  59.  
  60.  
  61.  
  62.  
  63. ventana.mainloop()
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement