Kalyax
2 years ago
2 changed files with 73 additions and 8 deletions
@ -1,9 +1,14 @@ |
|||||
from misc.parser import * |
from misc.window import * |
||||
from misc.tokenizer import * |
|
||||
|
|
||||
while True: |
app = Window() |
||||
calcul = str(input("Entrez votre calcul en NPI : ")) |
app.mainloop() |
||||
tokens = tokenize(calcul) |
|
||||
npi = shutting_yard(tokens) |
#from misc.parser import * |
||||
expression = npi2tree(npi) |
#from misc.tokenizer import * |
||||
print(expression.evalue()) |
|
||||
|
#while True: |
||||
|
# calcul = str(input("Entrez votre calcul en NPI : ")) |
||||
|
# tokens = tokenize(calcul) |
||||
|
# npi = shutting_yard(tokens) |
||||
|
# expression = npi2tree(npi) |
||||
|
# print(expression.evalue()) |
@ -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") |
Loading…
Reference in new issue