corentin.bollet
10 months ago
2 changed files with 55 additions and 3 deletions
@ -0,0 +1,46 @@ |
|||||
|
import tkinter as tk |
||||
|
from expression import * |
||||
|
|
||||
|
class Interface(tk.Frame): |
||||
|
def __init__(self, master): |
||||
|
self.master = master |
||||
|
tk.Frame.__init__(self, master) |
||||
|
|
||||
|
self.saisie_expression = tk.Entry(self.master) |
||||
|
self.saisie_expression.grid(row=0, column=0) |
||||
|
self.saisie_expression.bind("<Return>", lambda e : self.evaluer()) |
||||
|
self.saisie_expression.bind("<KP_Enter>", lambda e : self.evaluer()) |
||||
|
|
||||
|
|
||||
|
btn_calculer = tk.Button(self.master, text='évaluer', command=self.evaluer) |
||||
|
btn_calculer.grid(row=0, column=2) |
||||
|
|
||||
|
self.affichage_expression = tk.Label(self.master) |
||||
|
self.affichage_expression.grid(row=1, column=0) |
||||
|
|
||||
|
tk.Label(self.master, text = "=").grid(row=1, column=1) |
||||
|
|
||||
|
self.res = tk.Label(self.master) |
||||
|
self.res.grid(row=1, column=2) |
||||
|
|
||||
|
|
||||
|
def evaluer(self): |
||||
|
lst_expr = self.saisie_expression.get().split() |
||||
|
try: |
||||
|
arbre_expr = npi2tree(lst_expr) |
||||
|
self.affichage_expression.config(text = str(arbre_expr)) |
||||
|
self.res.config(text = arbre_expr.evalue()) |
||||
|
except IndexError: |
||||
|
self.affichage_expression.config(text = "Erreur") |
||||
|
self.res.config(text = "Erreur") |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
root = tk.Tk() |
||||
|
root.title("Calculatrice") |
||||
|
root.geometry("350x500") |
||||
|
hello_frame = Interface(root) |
||||
|
hello_frame.mainloop() |
Loading…
Reference in new issue