You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.7 KiB
93 lines
3.7 KiB
"""
|
|
Utilisation de gitea :
|
|
1er commit n'est valable comme message que pour le premier commit ;)
|
|
42 est la réponse universelle, mais pas un message valide, surtout
|
|
répété 6030 fois !!
|
|
|
|
Beaucoup de fonctions ou méthodes ne sont pas documentées.
|
|
|
|
class Expression:
|
|
pourquoi cette usine à gaz pour __str__ ??
|
|
Bien d'avoir laissé les tests.
|
|
|
|
fonction npi2tree:
|
|
dans quel cas pourrait-on avoir elem = None ??
|
|
que se passe-t-il si lst n'est pas bien formée ?
|
|
|
|
interface graphique:
|
|
bôcou de fôtes d'ortograf dent la dokumentassion !!!
|
|
pas de gestion des cas où l'expression est mal écrite (par exemple
|
|
2 2 = ou alors 2 + = ou encore 2+ =
|
|
petit bug si on continue un calcul après avoir tapé sur =
|
|
|
|
Note : 9/10
|
|
"""
|
|
|
|
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 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)
|
|
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"), 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 = 2
|
|
colonne = 0
|
|
for touche in touches:
|
|
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 == 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é ou les caractères sont espacés d'un espace 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()))
|
|
|
|
window = Fenetre()
|
|
window.mainloop()
|