from tkinter import * from modules.calculette1 import Calculette def ajouter_au_calcul(symbol): current_text = calc.get() calc.set(current_text + symbol) def ajouter_espace(): current_text = calc.get() calc.set(current_text + " ") def calculer_expression(): expression = calc.get().strip() resultat = calculatrice.calculer(expression) result_label.config(text="Résultat: " + str(resultat)) def effacer(): calc.set("") fenetre = Tk() fenetre.geometry("500x600") fenetre.title("Calculatrice NPI") calculatrice = Calculette() calcLabel = Label(fenetre, text="Expression en Notation Polonaise Inversée") calcLabel.pack(pady=10) calc = StringVar() calc.set("") saisie = Entry(fenetre, textvariable=calc, width=40) saisie.pack(pady=10) buttons_frame = Frame(fenetre) buttons_frame.pack(pady=10) buttons = [ ('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3), ('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3), ('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3), ('0', 4, 0), ('.', 4, 1), ('+', 4, 2), ('=', 4, 3), (' ', 5, 0) # Adding space button ] for (text, row, col) in buttons: if text == '=': Button(buttons_frame, text=text, width=10, height=3, command=calculer_expression).grid(row=row, column=col, padx=2, pady=2) elif text == ' ': Button(buttons_frame, text="SPACE", width=10, height=3, command=ajouter_espace).grid(row=row, column=col, padx=2, pady=2) else: Button(buttons_frame, text=text, width=10, height=3, command=lambda t=text: ajouter_au_calcul(t)).grid(row=row, column=col, padx=2, pady=2) Button(fenetre, text="EFFACER", width=40, command=effacer).pack(pady=10) result_label = Label(fenetre, text="", font=('Arial', 14)) result_label.pack(pady=10) # Exemple d'utilisation exemple = Label(fenetre, text="Exemple: '3 4 + 6 *' calcule (3+4)*6") exemple.pack() fenetre.mainloop()