Browse Source

dernières modifications

master
Enora 2 months ago
parent
commit
8341b94295
  1. 53
      calculatrice.py
  2. 2
      expression.py

53
calculatrice.py

@ -1,37 +1,68 @@
import tkinter as tk
from tkinter.constants import *
from tkinter import font
from expression import npi2tree
class Fenetre(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title("Calculatrice")
self.title("Calculatrice en polonais inversé")
self.geometry("400x600")
self.configure(bg='pink')
self.font= font.Font(family="Arial", size=30, weight="bold" )
#configuration des lignes et des colonnes afin de bien placer les boutons
self.grid_rowconfigure(0, weight = 4)
for i in range(1, 5):
self.grid_rowconfigure(1, weight = 1)
for i in range(2, 6):
self.grid_rowconfigure(i, weight = 1)
for j in range(4):
self.grid_columnconfigure(j, weight = 1)
#ajout de l'ecran et des boutons de la calculatrice
self.texte = ""
self.ecran = tk.Label(self, text=self.texte,font=("Arial", 60), bg="#EDFAF0")
self.ecran = tk.Label(self, text=self.texte,font=("Arial"), width = 5, height=5, bg="#EDFAF0")
self.ecran.grid(row = 0, column=0, columnspan=4, sticky="nsew")
touches = ("7", "8", "9", "+", "4", "5", "6", "-", "1", "2", "3", "*", "0", ",", "=", "/")
ligne = 1
touches = ( "7","8", "9", "4", "5", "6", "1", "2", "3", "0", ".")
ligne = 2
colonne = 0
for touche in touches:
tk.Button(self, text=touche,command=lambda t=touche:self.calculer(t), font = self.font).grid(row=ligne, column = colonne)
tk.Button(self, text=touche,command=lambda t=touche:self.affiche_boutons(t), font = self.font).grid(row=ligne, column = colonne)
colonne += 1
if colonne == 4:
if colonne == 3:
colonne = 0
ligne += 1
symboles = ("-", "+", "*", "/")
l=2
for symbole in symboles:
tk.Button(self, text=symbole,command=lambda s=symbole:self.affiche_boutons(s), font = self.font).grid(row=l, column = 3)
l += 1
tk.Button(self, text="=",command= self.calculer, font = self.font ).grid(row=5, column = 2)
tk.Button(self, text="supp",command = self.supprime, font = font.Font(family="Arial", size=10, weight="bold") ).grid(row=1, column = 2, columnspan = 2)
tk.Button(self, text="space",command = self.espace, font = font.Font(family="Arial", size=10, weight="bold") ).grid(row=1, column = 0, columnspan = 2)
def affiche_boutons(self, element):
"""affiche le boutons selectionner a l'ecran ainsi que dans le calcul"""
self.texte = self.texte + element
self.ecran.config(text=self.texte)
def supprime(self):
"""supprime toute l'expression notée"""
self.texte = ""
self.ecran.config(text = " ")
def espace(self):
"""rajoute un espace dans la chaine de caractère"""
self.texte = self.texte + " "
self.ecran.config(text=self.texte)
def calculer(self):
"""calcul l'expression ecrite en polonais inversé et l'affiche en notation infixe suivit du resultat"""
lst = self.texte.split(" ")
e = npi2tree(lst)
self.ecran.config(text = str(e) + "=" + str(e.evalue()))
def calculer(self, element):
#if element == "=":
self.texte = self.texte + element
self.ecran.config(text=self.texte)
window = Fenetre()
window.mainloop()

2
expression.py

@ -63,6 +63,6 @@ if __name__ == "__main__":
Expression(6, None, None))
print(exp.evalue())
print(exp)
e = npi2tree([-6, 4, 3, "+", "-"])
e = npi2tree(["6.5", "4", "3", "+", "-"])
print(e)
print(e.evalue())
Loading…
Cancel
Save