• Inicio
  • Blog
  • Creandolared
  • Buscar
  • Ingresar
  • Registrarse

    • Hack x Crack - Comunidad de Seguridad informática »
    • Programación »
    • Scripting »
    • Python »
    • Calculadora con interfaz gráfica [Tkinter]
    ¿Quieres aprender de páginas web? Visita la comunidad Creandolared
    • Imprimir
    Páginas: [1]   Ir Abajo

    Autor Tema: Calculadora con interfaz gráfica [Tkinter]  (Leído 546 veces)

    Desconectado R3LI4NT

    • { L2 } Nativo Digital
    • **
    • Mensajes: 145
    • El poder del usuario radica en su ANONIMATO.
      • Ver Perfil
      • GitHub
    Calculadora con interfaz gráfica [Tkinter]
    « en: Enero 22, 2021, 04:21:36 am »


    Código:
    Código: Python
    1. from tkinter import *
    2.  
    3.  
    4. operador = 0
    5.  
    6.  
    7. def digito(valor):
    8.         global operador
    9.         ingreso.insert(operador, valor)
    10.         operador += 1
    11.  
    12.  
    13. def calculo():
    14.         cuenta = ingreso.get()
    15.         resultado = eval(cuenta)
    16.         ingreso.delete(0, END)
    17.         ingreso.insert(0, resultado)
    18.         operador = 0
    19.  
    20. def borrar():
    21.         ingreso.delete(0, END)
    22.         operador = 0   
    23.  
    24.  
    25. app = Tk()
    26.  
    27. app.title("Calculadora")
    28. app.iconbitmap("logo.ico")
    29. app.geometry("353x400")
    30. app.config(cursor="pirate")
    31. app.config(bg="SpringGreen2")
    32. app.config(bd="10")
    33.  
    34.  
    35. ingreso = Entry (bd=10, font=("Cursive", 20))
    36. ingreso.grid(row=0, column=0, columnspan=4, padx=5, pady=5)
    37.  
    38.  
    39. btn_1 = Button(app, text="1", width=4, height=2, command=lambda:digito(1))
    40. btn_2 = Button(app, text="2", width=4, height=2, command=lambda:digito(2))
    41. btn_3 = Button(app, text="3", width=4, height=2, command=lambda:digito(3))
    42. btn_4 = Button(app, text="4", width=4, height=2, command=lambda:digito(4))
    43. btn_5 = Button(app, text="5", width=4, height=2, command=lambda:digito(5))
    44. btn_6 = Button(app, text="6", width=4, height=2, command=lambda:digito(6))
    45. btn_7 = Button(app, text="7", width=4, height=2, command=lambda:digito(7))
    46. btn_8 = Button(app, text="8", width=4, height=2, command=lambda:digito(8))
    47. btn_9 = Button(app, text="9", width=4, height=2, command=lambda:digito(9))
    48. btn_0 = Button(app, text="0", width=13, height=2, command=lambda:digito(0))
    49.  
    50. btn_borrar = Button(app, text="DEL", width=5, height=2, command=lambda:borrar())
    51. btn_borrar.config(bg="gray44", font=("slant"))
    52. btn_punto = Button(app, text=".", width=5, height=2, command=lambda:digito("."))
    53. btn_paren1 = Button(app, text="(", width=5, height=2, command=lambda:digito("("))
    54. btn_paren2 = Button(app, text=")", width=5, height=2, command=lambda:digito(")"))
    55.  
    56.  
    57. btn_div = Button(app, text="/", width=5, height=2, command=lambda:digito("/"))
    58. btn_div.config(bg="dark green", bd=4, fg="white")
    59. btn_multi = Button(app, text="*", width=5, height=2, command=lambda:digito("*"))
    60. btn_multi.config(bg="deep sky blue", bd=4, fg="white")
    61. btn_suma = Button(app, text="+", width=5, height=2, command=lambda:digito("+"))
    62. btn_suma.config(bg="red", bd=4, fg="white")
    63. btn_resta = Button(app, text="-", width=5, height=2, command=lambda:digito("-"))
    64. btn_resta.config(bg="gold", bd=4, fg="white")
    65. btn_igual = Button(app, text="=", width=5, height=2, command=lambda:calculo())
    66. btn_igual.config(bg="blue2", highlightthickness=6, bd=4, fg="white")
    67.  
    68.  
    69. btn_borrar.grid(row=1, column=0, padx=5, pady=5)
    70. btn_paren1.grid(row=1, column=1, padx=5, pady=5)
    71. btn_paren2.config(bg="ghost white")
    72. btn_paren2.grid(row=1, column=2, padx=5, pady=5)
    73. btn_paren2.config(bg="ghost white")
    74. btn_div.grid(row=1, column=3, padx=5, pady=5)
    75.  
    76.  
    77. btn_7.grid(row=2, column=0, padx=3, pady=3)
    78. btn_7.config(bg="ghost white")
    79. btn_8.grid(row=2, column=1, padx=3, pady=3)
    80. btn_8.config(bg="ghost white")
    81. btn_9.grid(row=2, column=2, padx=3, pady=3)
    82. btn_9.config(bg="ghost white")
    83. btn_multi.grid(row=2, column=3, padx=5, pady=5)
    84.  
    85.  
    86. btn_4.grid(row=3, column=0, padx=3, pady=3)
    87. btn_4.config(bg="ghost white")
    88. btn_5.grid(row=3, column=1, padx=3, pady=3)
    89. btn_5.config(bg="ghost white")
    90. btn_6.grid(row=3, column=2, padx=3, pady=3)
    91. btn_6.config(bg="ghost white")
    92. btn_suma.grid(row=3, column=3, padx=5, pady=5)
    93.  
    94.  
    95. btn_1.grid(row=4, column=0, padx=3, pady=3)
    96. btn_1.config(bg="ghost white")
    97. btn_2.grid(row=4, column=1, padx=3, pady=3)
    98. btn_2.config(bg="ghost white")
    99. btn_3.grid(row=4, column=2, padx=3, pady=3)
    100. btn_3.config(bg="ghost white")
    101. btn_resta.grid(row=4, column=3, padx=5, pady=5)
    102.  
    103. btn_0.grid(row=5, column=0, columnspan=2, padx=5, pady=5)
    104. btn_0.config(bg="ghost white")
    105. btn_punto.grid(row=5, column=2, padx=5, pady=5)
    106. btn_punto.config(bg="ghost white")
    107. btn_igual.grid(row=5, column=3, padx=5, pady=5)
    108.  
    109.  
    110. app.mainloop()
    111.  

    Github: https://github.com/R3LI4NT/calculadora-tkinter
    En línea

    • Imprimir
    Páginas: [1]   Ir Arriba
    • Hack x Crack - Comunidad de Seguridad informática »
    • Programación »
    • Scripting »
    • Python »
    • Calculadora con interfaz gráfica [Tkinter]
     

    • SMF | SMF © 2013, Simple Machines
    • XHTML
    • RSS
    • WAP2
    Va un mudo y le dice a un sordo: Hack x Crack usa cookies. Pues eso... Learn more