Browse Source

window

master
alexandre.aboulin 2 years ago
parent
commit
42ce566289
  1. 33
      misc/window.py

33
misc/window.py

@ -1,13 +1,14 @@
from tkinter import Tk, Button, Label, StringVar
from tkinter import Tk, Button, Label, StringVar, Entry
from misc.parser import *
from misc.tokenizer import *
from lib.File import File_chaine as File
class Window(Tk):
def __init__(self):
Tk.__init__(self)
self.title("test")
self.geometry("400x500")
self.geometry("500x600")
self.resizable(False, False)
self.layout()
@ -15,11 +16,16 @@ class Window(Tk):
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)
self.label = Label(textvariable=self.text, background="#eaeaea", font=("Arial", 20))
self.label.pack(fill="x")
self.input = Entry(textvariable=self.text)
self.input.pack(fill="x")
Label(text="Pensez aux parenthèses et à utiliser des espaces avec EVAL_NPI", font=("Arial", 11)).pack(fill='x')
#BOUTTONS
bouttons = ["1", "2", "3", "+", "-", "4", "5", "6", "*", "/", "7", "8", "9", "^", "sqrt", "EVAL", "0", "DEL", "CLEAR", "exp", "(", ")", ".", "sin", "cos"]
bouttons = ["1", "2", "3", "+", "-", "4", "5", "6", "*", "/", "7", "8", "9", "^", "sqrt", "EVAL", "0", "DEL", "CLEAR", "exp", "(", ")", ".", "sin", "cos", "EVAL_NPI", "ESPACE"]
col = 0
row = 0
for b in bouttons:
@ -34,10 +40,14 @@ class Window(Tk):
cmd = self.delete
elif b == "CLEAR":
cmd = self.clear
elif b == "EVAL_NPI":
cmd = self.evalue_npi
elif b == "ESPACE":
cmd = lambda: self.write(" ")
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)
Button(self, text=b, width=6, height=1, command=cmd).place(x=10+100*col, y=100+40*row)
col += 1
@ -52,6 +62,17 @@ class Window(Tk):
def clear(self):
self.text.set("")
def evalue_npi(self):
try:
tokens = tokenize(self.text.get())
file = File()
for token in tokens:
file.enfiler(token)
exp = npi2tree(file)
self.text.set(exp.evalue())
except:
self.text.set("Erreur NPI")
def evalue(self):
try:
exp = npi2tree(shutting_yard(tokenize(self.text.get())))

Loading…
Cancel
Save