|
1 |
| -# Made by abhra kanti Dubey |
2 | 1 | # In this program you ask it about any topic and it will show you the data from wikipedia
|
3 | 2 | # pip install wikipedia
|
4 | 3 |
|
5 | 4 | import wikipedia
|
6 | 5 | import tkinter as tk
|
7 |
| -from tkinter import * |
8 |
| -import PIL as ImageTK |
| 6 | +from tkinter import Label, Button, Entry, Text, messagebox, SOLID, GROOVE, StringVar, WORD, END |
| 7 | +#import PIL as ImageTK |
9 | 8 | from tkinter import messagebox
|
10 | 9 |
|
11 | 10 |
|
12 |
| -root = tk.Tk() |
13 |
| -root.title("WIKIPEDIA SEARCH") |
14 |
| -root.geometry("1920x1080") |
15 |
| - |
16 |
| - |
17 |
| -def summary(): |
18 |
| - query = wikipedia.page(question.get()) |
19 |
| - answer = Text( |
20 |
| - root, |
21 |
| - height=100, |
22 |
| - width=160, |
23 |
| - font=("Arial", 14), |
24 |
| - wrap=WORD, |
25 |
| - bg="#7CEBC6", |
26 |
| - fg="black", |
27 |
| - ) |
28 |
| - answer.insert(END, (query.summary)) |
29 |
| - answer.pack() |
30 |
| - |
31 |
| - |
32 |
| -lbl1 = Label( |
33 |
| - root, |
34 |
| - text="WIKIPEDIA SUMMARY TELLER BY ABHRA ", |
35 |
| - font=("Verdana", 25, "bold"), |
36 |
| - width=50, |
37 |
| - bg="yellow", |
38 |
| - fg="red", |
39 |
| - relief=SOLID, |
40 |
| -) |
41 |
| -lbl1.pack(padx=10, pady=15) |
42 |
| - |
43 |
| -question = StringVar() |
44 |
| - |
45 |
| -quesbox = Entry( |
46 |
| - root, |
47 |
| - text="TELL ME YOUR QUESTION", |
48 |
| - font=("Verdana", 20, "italic"), |
49 |
| - width=80, |
50 |
| - textvariable=question, |
51 |
| - relief=GROOVE, |
52 |
| - bd=10, |
53 |
| -).pack() |
54 |
| - |
55 |
| -searchbtn = Button( |
56 |
| - root, |
57 |
| - text="SEARCH", |
58 |
| - font=("Callibri", 18, "bold"), |
59 |
| - width=30, |
60 |
| - relief=GROOVE, |
61 |
| - bg="#4cd137", |
62 |
| - bd=3, |
63 |
| - command=summary, |
64 |
| -).pack() |
65 |
| - |
66 |
| - |
67 |
| -root.mainloop() |
| 11 | +class main(): |
| 12 | + def __init__(self, root): |
| 13 | + self.root = root |
| 14 | + |
| 15 | + self.root.title("WIKIPEDIA SEARCH") |
| 16 | + self.root.geometry("1920x1080") |
| 17 | + |
| 18 | + self.lbl1 = Label( |
| 19 | + root, |
| 20 | + text="WIKIPEDIA SUMMARY", |
| 21 | + font=("Verdana", 25, "bold"), |
| 22 | + width=50, |
| 23 | + bg="yellow", |
| 24 | + fg="red", |
| 25 | + relief=SOLID, |
| 26 | + ) |
| 27 | + self.lbl1.pack(padx=10, pady=15) |
| 28 | + |
| 29 | + self.question = StringVar() |
| 30 | + |
| 31 | + self.quesbox = Entry( |
| 32 | + root, |
| 33 | + text="TELL ME YOUR QUESTION", |
| 34 | + font=("Verdana", 20, "italic"), |
| 35 | + width=80, |
| 36 | + textvariable=self.question, |
| 37 | + relief=GROOVE, |
| 38 | + bd=10, |
| 39 | + ) |
| 40 | + self.quesbox.pack() |
| 41 | + |
| 42 | + self.searchbtn = Button( |
| 43 | + root, |
| 44 | + text="SEARCH", |
| 45 | + font=("Callibri", 18, "bold"), |
| 46 | + width=30, |
| 47 | + relief=GROOVE, |
| 48 | + bg="#4cd137", |
| 49 | + bd=3, |
| 50 | + command=lambda:self.summary("None"), |
| 51 | + ) |
| 52 | + self.searchbtn.pack() |
| 53 | + |
| 54 | + self.answer = Text( |
| 55 | + root, |
| 56 | + height=100, |
| 57 | + width=160, |
| 58 | + font=("Arial", 14), |
| 59 | + wrap=WORD, |
| 60 | + bg="#7CEBC6", |
| 61 | + fg="black", |
| 62 | + ) |
| 63 | + |
| 64 | + self.root.bind("<Return>", self.summary) |
| 65 | + |
| 66 | + def summary(self, event): |
| 67 | + self.searchbtn["text"] = "Searching..." |
| 68 | + try: |
| 69 | + self.query = wikipedia.page(self.question.get(), auto_suggest=True) |
| 70 | + self.quesbox.delete(0, 'end') |
| 71 | + self.answer.delete('1.0', END) |
| 72 | + self.answer.insert(END, (self.query.summary)) |
| 73 | + |
| 74 | + self.answer.pack() |
| 75 | + except Exception as e: |
| 76 | + error_msg = f"{e}" |
| 77 | + messagebox.showerror("Error", error_msg) |
| 78 | + |
| 79 | + self.searchbtn["text"] = "Search" |
| 80 | + |
| 81 | + |
| 82 | + # Wikipeida page returns to many pages |
| 83 | + |
| 84 | +if __name__ == "__main__": |
| 85 | + root = tk.Tk() |
| 86 | + main(root) |
| 87 | + root.mainloop() |
0 commit comments