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.

46 lines
1.4 KiB

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()