elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [Python3-tkinter ejemplo de calculadora]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Python3-tkinter ejemplo de calculadora]  (Leído 3,320 veces)
reconFito

Desconectado Desconectado

Mensajes: 31


Ver Perfil
[Python3-tkinter ejemplo de calculadora]
« en: 8 Marzo 2020, 16:38 pm »



Hola a todos aquí les dejo una calculadora sin funcionalidad.
Espero les guste o puede que no


Código
  1. from tkinter import Tk
  2. from tkinter import ttk
  3. from math import floor
  4.  
  5.  
  6. class App(ttk.Frame):
  7.    def __init__(self, master):
  8.        super().__init__(master)
  9.        self.pack()
  10.        # Variables
  11.        self.screen = None
  12.        # Metodos de clase
  13.        self.style_widgets()
  14.        self.create_widgets()
  15.  
  16.    # Estilos de los componentes del Frame
  17.    def style_widgets(self):
  18.        # estilos generales
  19.        ttk.Style().configure("TEntry", foreground="#00000a9")
  20.        ttk.Style().configure("TButton", width=10, padding=(
  21.            15, 10), relief=ttk.tkinter.FLAT)
  22.        ttk.Style().configure("E.TButton", background="#709234")
  23.        ttk.Style().configure("OP.TButton", background="#cccccc")
  24.  
  25.    def create_widgets(self):
  26.        self.screen = ttk.Entry(self)
  27.        self.screen.config(justify=ttk.tkinter.RIGHT)
  28.        self.screen.grid(row=1, column=1, ipady=20,
  29.                         columnspan=4, sticky="NSWE")
  30.  
  31.        # Crear botones
  32.        dic_buttons = {}  # diccionario de botones
  33.        for i in range(1, 13):
  34.            dic_buttons[f"btn{i}"] = ttk.Button(self, text=f"{i}")
  35.  
  36.        dic_buttons.update([("btnmul", ttk.Button(self, text="x")),
  37.                            ("btndif", ttk.Button(self, text="-")),
  38.                            ("btnplus", ttk.Button(self, text="+")),
  39.                            ("btnmod", ttk.Button(self, text="/"))])
  40.  
  41.        dic_buttons["btn9"].grid(row=2, column=1)
  42.        dic_buttons["btn8"].grid(row=2, column=2)
  43.        dic_buttons["btn7"].grid(row=2, column=3)
  44.        dic_buttons["btnmul"].grid(row=2, column=4)
  45.        dic_buttons["btn6"].grid(row=3, column=1)
  46.        dic_buttons["btn5"].grid(row=3, column=2)
  47.        dic_buttons["btn4"].grid(row=3, column=3)
  48.        dic_buttons["btndif"].grid(row=3, column=4)
  49.        dic_buttons["btn3"].grid(row=4, column=1)
  50.        dic_buttons["btn2"].grid(row=4, column=2)
  51.        dic_buttons["btn1"].grid(row=4, column=3)
  52.        dic_buttons["btnplus"].grid(row=4, column=4)
  53.        dic_buttons["btn10"].grid(row=5, column=1)
  54.        dic_buttons["btn11"].grid(row=5, column=2)
  55.        dic_buttons["btn12"].grid(row=5, column=3)
  56.        dic_buttons["btnmod"].grid(row=5, column=4)
  57.  
  58.        dic_buttons["btn10"].config(text=",")
  59.        dic_buttons["btn11"].config(text="0")
  60.        dic_buttons["btn12"].config(text="=", style="E.TButton")
  61.  
  62.        # print(dic_buttons.keys())
  63.        dic_buttons["btnmul"].config(style="OP.TButton")
  64.        dic_buttons["btndif"].config(style="OP.TButton")
  65.        dic_buttons["btnplus"].config(style="OP.TButton")
  66.        dic_buttons["btnmod"].config(style="OP.TButton")
  67.  
  68.  
  69. if __name__ == "__main__":
  70.    root = Tk()
  71.    root.resizable(False, False)
  72.    root.title("ttk Example")
  73.    app = App(root)
  74.    app.mainloop()
  75.  
  76.  


En línea

tincopasan


Desconectado Desconectado

Mensajes: 1.286

No es lo mismo conocer el camino que recorrerlo.


Ver Perfil
Re: [Python3-tkinter ejemplo de calculadora]
« Respuesta #1 en: 9 Marzo 2020, 19:54 pm »

Hola:

Citar
Espero les guste o puede que no
no me gusta. el orden de los números, lo más simple es que vayan de menor a mayor de izquierda a derecha y no al contrario. Más allá de la simplicidad y la falta de funcionalidad, le faltan los botones más básicos como el de poner todo a 0 y el de retroceder en caso de un mal tipeo.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Como Crear Una Ventana en C, por ejemplo una calculadora « 1 2 »
Programación C/C++
fernando.fetis 19 31,435 Último mensaje 17 Julio 2010, 18:58 pm
por fernando.fetis
Python 2.7.5 o Python3
Scripting
TrokaMc 1 2,020 Último mensaje 3 Enero 2014, 21:44 pm
por Max00355
[Python3 + tkinter] Ayuda ventanas en cascada tkinter
Scripting
darkweb64 2 3,655 Último mensaje 11 Diciembre 2015, 18:04 pm
por darkweb64
[Python3 + tkinter] Ayuda con combobox dependiente
Scripting
darkweb64 0 2,394 Último mensaje 8 Febrero 2017, 20:37 pm
por darkweb64
Calculadora en Python con Tkinter! (v1.2)
Scripting
n1sen 9 10,966 Último mensaje 8 Febrero 2019, 18:43 pm
por xiquipython
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines