-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (51 loc) · 1.5 KB
/
main.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
import tkinter
from tkinter import *
import wikipedia
class WikiApp:
def __init__(self):
self.root = Tk()
self.root.title('Wikipedia Summary App')
self.root.geometry("770x650")
self.root.resizable(False, False)
self.root.config(bg='gray')
self.frame = Frame(
self.root,
)
self.frame.pack()
self.entry = Entry(
self.frame,
bd=2,
width=65,
bg='#FFF',
)
self.entry.pack(side=LEFT, ipady=6, expand=True, fill='y')
self.search_btn = Button(
self.frame,
bd=5,
text='Search',
command=self.get_summary,
bg="#FFF",
)
self.search_btn.pack(side=LEFT, expand=True, fill='y')
self.text = Text(
self.root,
bd=0,
highlightthickness=0,
bg='#FFF',
)
self.text.pack(expand=True, fill='both')
def get_summary(self):
self.text.delete(1.0, END)
query = self.entry.get()
try:
result = wikipedia.summary(query)
except wikipedia.exceptions.DisambiguationError as e:
query = e.options[0]
result = wikipedia.summary(query)
except Exception as ex:
result = 'Something went wrong!'
self.text.insert(INSERT, result)
def mainloop(self):
self.root.mainloop()
wiki_app = WikiApp()
wiki_app.mainloop()