bollet.c
9 months ago
4 changed files with 169 additions and 93 deletions
@ -1,46 +0,0 @@ |
|||
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