Browse Source

interface graphique qui marche

master
Kalyax 2 years ago
parent
commit
f3898809d6
  1. 21
      main.py
  2. 60
      misc/window.py

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

60
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")
Loading…
Cancel
Save