-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ganjoor.py
67 lines (45 loc) · 1.88 KB
/
Ganjoor.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
from tkinter import *
import urllib.request, json
import webbrowser
def main():
root = Tk()
root.title('گنجور')
first = StringVar()
second = StringVar()
poetName = StringVar()
websiteAdd = StringVar()
def callback(event):
webbrowser.open_new((data['url']))
def btncallback():
try:
with urllib.request.urlopen("http://c.ganjoor.net/beyt-json.php") as url:
data = json.loads(url.read().decode())
first.set(data['m1'])
second.set(data['m2'])
websiteAdd.set(data['url'])
poetName.set(data['poet'])
print(data)
except:
websiteAdd.set("اینترنت وصل نیست")
#Label(root, text="Hello, world!").pack()
Label(root, textvariable=first, anchor=CENTER, width=40, font=("B Nazanin", 16)).grid(column=1, row=0)
Label(root, textvariable=second, anchor=CENTER, width=40, font=("B Nazanin", 16)).grid(column=0, row=0)
b = Button(root, text="Next!", command=btncallback)
b.grid(column=2, row=0)
label3 = Label(root, textvariable=websiteAdd, anchor=CENTER, font=("Arial", 16),fg="blue", cursor="hand2")
label3.grid(column=0, row=1)
label3.bind("<Button-1>", callback)
Label(root, textvariable=poetName, anchor=CENTER, font=("B Nazanin", 16)).grid(column=1, row=1)
Label(root, text='شاعر:', anchor=CENTER, font=("B Nazanin", 16)).grid(column=2, row=1)
try:
with urllib.request.urlopen("http://c.ganjoor.net/beyt-json.php") as url:
data = json.loads(url.read().decode())
first.set(data['m1'])
second.set(data['m2'])
websiteAdd.set(data['url'])
poetName.set(data['poet'])
print(data)
except:
websiteAdd.set("اینترنت وصل نیست")
root.mainloop()
if __name__ == "__main__": main()