|
@ -2,73 +2,65 @@ from tkinter import * |
|
|
from modules.calculette import Calculette |
|
|
from modules.calculette import Calculette |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from tkinter import * |
|
|
|
|
|
from modules.calculette import Calculette |
|
|
|
|
|
|
|
|
def ajouter_au_calcul(symbol): |
|
|
def ajouter_au_calcul(symbol): |
|
|
'''Ajoute un symbole à la saisie''' |
|
|
|
|
|
current_text = calc.get() |
|
|
current_text = calc.get() |
|
|
calc.set(current_text + symbol) |
|
|
calc.set(current_text + symbol) |
|
|
|
|
|
|
|
|
|
|
|
def ajouter_espace(): |
|
|
|
|
|
current_text = calc.get() |
|
|
|
|
|
calc.set(current_text + " ") |
|
|
|
|
|
|
|
|
def calculer_expression(): |
|
|
def calculer_expression(): |
|
|
'''Calcule l'expression saisie''' |
|
|
expression = calc.get().strip() |
|
|
expression = calc.get() |
|
|
|
|
|
resultat = calculatrice.calculer(expression) |
|
|
resultat = calculatrice.calculer(expression) |
|
|
result_label.config(text="Résultat: " + str(resultat)) |
|
|
result_label.config(text="Résultat: " + str(resultat)) |
|
|
|
|
|
|
|
|
def effacer(): |
|
|
def effacer(): |
|
|
'''Efface la saisie''' |
|
|
|
|
|
calc.set("") |
|
|
calc.set("") |
|
|
|
|
|
|
|
|
fenetre = Tk() |
|
|
fenetre = Tk() |
|
|
fenetre.geometry("350x300") |
|
|
fenetre.geometry("400x500") |
|
|
fenetre.title("Calculatrice") |
|
|
fenetre.title("Calculatrice NPI") |
|
|
|
|
|
|
|
|
calculatrice = Calculette() |
|
|
calculatrice = Calculette() |
|
|
|
|
|
|
|
|
calcLabel = Label(fenetre, text="Saisir le calcul") |
|
|
calcLabel = Label(fenetre, text="Expression en Notation Polonaise Inversée") |
|
|
|
|
|
calcLabel.pack(pady=10) |
|
|
from calculette import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fenetre=Tk() |
|
|
|
|
|
fenetre.title("Calculatrice") |
|
|
|
|
|
|
|
|
|
|
|
calcLabel = Label(fenetre, text="saisir le calcul") |
|
|
|
|
|
calcLabel.pack() |
|
|
|
|
|
|
|
|
|
|
|
calc = StringVar() |
|
|
calc = StringVar() |
|
|
calc.set("") |
|
|
calc.set("") |
|
|
|
|
|
|
|
|
saisie = Entry(fenetre, textvariable=calc, width=40) |
|
|
saisie = Entry(fenetre, textvariable=calc, width=40) |
|
|
saisie.pack() |
|
|
saisie.pack(pady=10) |
|
|
|
|
|
|
|
|
buttons_frame = Frame(fenetre) |
|
|
buttons_frame = Frame(fenetre) |
|
|
buttons_frame.pack() |
|
|
buttons_frame.pack(pady=10) |
|
|
#matrices des boutons |
|
|
|
|
|
buttons = [ |
|
|
buttons = [ |
|
|
('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3), |
|
|
('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3), |
|
|
('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3), |
|
|
('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3), |
|
|
('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3), |
|
|
('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3), |
|
|
('0', 4, 0), ('.', 4, 1), ('+', 4, 2), ('=', 4, 3), |
|
|
('0', 4, 0), ('.', 4, 1), ('+', 4, 2), ('=', 4, 3), |
|
|
|
|
|
(' ', 5, 0) # Adding space button |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
for (text, row, col) in buttons: |
|
|
for (text, row, col) in buttons: |
|
|
if text == '=': |
|
|
if text == '=': |
|
|
Button(buttons_frame, text=text, width=10, height=3, command=calculer_expression).grid(row=row, column=col) |
|
|
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: |
|
|
else: |
|
|
Button(buttons_frame, text=text, width=10, height=3, command=lambda t=text: ajouter_au_calcul(t)).grid(row=row, column=col) |
|
|
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() |
|
|
|
|
|
|
|
|
|
|
|
result_label = Label(fenetre, text="") |
|
|
Button(fenetre, text="EFFACER", width=40, command=effacer).pack(pady=10) |
|
|
result_label.pack() |
|
|
|
|
|
|
|
|
|
|
|
fenetre.mainloop() |
|
|
result_label = Label(fenetre, text="", font=('Arial', 14)) |
|
|
|
|
|
result_label.pack(pady=10) |
|
|
saisie = Entry(fenetre, textvariable=calc, width=10) |
|
|
|
|
|
saisie.pack() |
|
|
|
|
|
|
|
|
|
|
|
bouton1 = Button(fenetre, text="CALCULER", width=8) |
|
|
# Exemple d'utilisation |
|
|
bouton1.pack() |
|
|
exemple = Label(fenetre, text="Exemple: '3 4 + 6 *' calcule (3+4)*6") |
|
|
|
|
|
exemple.pack() |
|
|
|
|
|
|
|
|
fenetre.mainloop() |
|
|
fenetre.mainloop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|