-
Notifications
You must be signed in to change notification settings - Fork 39
/
wolframAlpha.py
69 lines (53 loc) · 1.82 KB
/
wolframAlpha.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import wolframalpha
import base64
import tkinter as tk
from urllib.request import urlopen
API_KEY = 'INSERT YOUR API KEY HERE'
client = wolframalpha.Client(API_KEY)
def math():
eq = entry1.get()
res = client.query(eq.strip(), params=(("format", "image,plaintext"),))
data = {}
for p in res.pods:
for s in p.subpods:
if s.img.alt.lower() == "root plot":
data['rootPlot'] = s.img.src
elif s.img.alt.lower() == "number line":
data['numberLine'] = s.img.src
data['results'] = [i.texts for i in list(res.results)][0]
print(data)
image1_url = data['rootPlot']
image2_url = data['numberLine']
image1_byt = urlopen(image1_url).read()
image1_b64 = base64.encodebytes(image1_byt)
photo1 = tk.PhotoImage(data=image1_b64)
image2_byt = urlopen(image2_url).read()
image2_b64 = base64.encodebytes(image2_byt)
photo2 = tk.PhotoImage(data=image2_b64)
canvas.photo1 = photo1
canvas.photo2 = photo2
canvas.create_image(10, 30, image=canvas.photo1, anchor='nw')
canvas.create_text(175,40,fill="darkblue",font="Arial 10",text="Root Plot")
# canvas.pack()
canvas.create_image(10, 240, image=canvas.photo2, anchor='nw')
canvas.create_text(175,230,fill="darkblue",font="Arial 10",text="Number Line")
canvas.create_text(175,320,fill="darkblue",font="Arial 15",text=data['results'])
root = tk.Tk()
root.title("Math Visualizion")
# a little more than width and height of image
w = 500
h = 500
x = 50
y = 100
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# create a white canvas
canvas = tk.Canvas(bg='white')
canvas.config(height=350)
canvas.pack()
# entry box
entry1 = tk.Entry(root)
canvas.create_window(150, 15, window=entry1)
# submit button
submit = tk.Button(text='Solve',command=math,height=1, width = 3)
canvas.create_window(280, 15, window=submit)
root.mainloop()