Amazing-Python-Scripts
55 строк · 1.7 Кб
1from tkinter import Tk, Frame, Toplevel, Entry, Button, Text, Scrollbar, END, INSERT
2from tkinter.messagebox import showerror
3from mediawiki import MediaWiki
4wikipedia = MediaWiki()
5
6# Function to get summary using wikipedia module and display it
7
8
9def get_summary():
10try:
11# clear text area
12answer.delete(1.0, END)
13# show summary in text area
14topic = keyword_entry.get()
15p = wikipedia.page(topic)
16answer.insert(INSERT, p.summary)
17except Exception as error:
18showerror("Error", error)
19
20
21# create a GUI window and configure it
22root = Tk()
23root.title("Wikipedia Summary")
24root.geometry("770x650")
25root.resizable(False, False)
26root.configure(bg="dark grey")
27
28# create a frame for entry and button
29top_frame = Frame(root, bg="dark grey")
30top_frame.pack(side="top", fill="x", padx=50, pady=10)
31
32# create a frame for text area where summary will be displayed
33bottom_frame = Frame(root, bg="dark grey")
34bottom_frame.pack(side="top", fill="x", padx=10, pady=10)
35
36# create a entry box where user can enter a keyword
37keyword_entry = Entry(top_frame, font=("Arial", 20, "bold"), width=25, bd=4)
38keyword_entry.pack(side="left", ipady=6)
39
40# create a search button
41search_button = Button(top_frame, text="Get Summary", font=(
42"Arial", 16, "bold"), width=15, bd=4, command=get_summary)
43search_button.pack(side="right")
44
45# create a scroll bar for text area
46scroll = Scrollbar(bottom_frame)
47
48# create a text area where summary will be displayed
49answer = Text(bottom_frame, font=("Arial", 18), fg="black",
50width=55, height=20, bd=5, yscrollcommand=scroll.set)
51answer.pack(side="left", fill="y")
52scroll.pack(side="left", fill="y")
53
54# start the GUI
55root.mainloop()
56