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