diff --git a/main.py b/main.py index 0d3b2c7..0507578 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,14 @@ -from misc.parser import * -from misc.tokenizer import * +from misc.window import * -while True: - calcul = str(input("Entrez votre calcul en NPI : ")) - tokens = tokenize(calcul) - npi = shutting_yard(tokens) - expression = npi2tree(npi) - print(expression.evalue()) \ No newline at end of file +app = Window() +app.mainloop() + +#from misc.parser import * +#from misc.tokenizer import * + +#while True: +# calcul = str(input("Entrez votre calcul en NPI : ")) +# tokens = tokenize(calcul) +# npi = shutting_yard(tokens) +# expression = npi2tree(npi) +# print(expression.evalue()) \ No newline at end of file diff --git a/misc/window.py b/misc/window.py new file mode 100644 index 0000000..e7108f9 --- /dev/null +++ b/misc/window.py @@ -0,0 +1,60 @@ +from tkinter import Tk, Button, Label, StringVar +from misc.parser import * +from misc.tokenizer import * + +class Window(Tk): + + def __init__(self): + Tk.__init__(self) + self.title("test") + self.geometry("400x500") + self.resizable(False, False) + + self.layout() + + def layout(self): + #TEXT + self.text = StringVar(value="") + self.label = Label(textvariable=self.text, background="#eaeaea", borderwidth=2, relief="solid", font=("Arial", 20)) + self.label.pack(fill="x")#.place(x=0, y=0) + + #BOUTTONS + bouttons = ["1", "2", "3", "+", "-", "4", "5", "6", "*", "/", "7", "8", "9", "^", "sqrt", "EVAL", "0", "DEL", "CLEAR", "exp", "(", ")", ".", "sin", "cos"] + col = 0 + row = 0 + for b in bouttons: + if col == 5: + col = 0 + row += 1 + + cmd = None + if b == "EVAL": + cmd = self.evalue + elif b == "DEL": + cmd = self.delete + elif b == "CLEAR": + cmd = self.clear + else: + cmd = lambda text = b: self.write(str(text)) + + Button(self, text=b, width=5, height=1, command=cmd).place(x=40+50*col, y=250+30*row) + + col += 1 + + def write(self, text): + current = self.text.get() + self.text.set(current + text) + + def delete(self): + current = self.text.get() + self.text.set(current[:-1]) + + def clear(self): + self.text.set("") + + def evalue(self): + try: + exp = npi2tree(shutting_yard(tokenize(self.text.get()))) + self.text.set(exp.evalue()) + except: + self.text.set("Erreur")