Amazing-Python-Scripts

Форк
0
55 строк · 1.7 Кб
1
from tkinter import Tk, Frame, Toplevel, Entry, Button, Text, Scrollbar, END, INSERT
2
from tkinter.messagebox import showerror
3
from mediawiki import MediaWiki
4
wikipedia = MediaWiki()
5

6
# Function to get summary using wikipedia module and display it
7

8

9
def get_summary():
10
    try:
11
        # clear text area
12
        answer.delete(1.0, END)
13
        # show summary in text area
14
        topic = keyword_entry.get()
15
        p = wikipedia.page(topic)
16
        answer.insert(INSERT, p.summary)
17
    except Exception as error:
18
        showerror("Error", error)
19

20

21
# create a GUI window and configure it
22
root = Tk()
23
root.title("Wikipedia Summary")
24
root.geometry("770x650")
25
root.resizable(False, False)
26
root.configure(bg="dark grey")
27

28
# create a frame for entry and button
29
top_frame = Frame(root, bg="dark grey")
30
top_frame.pack(side="top", fill="x", padx=50, pady=10)
31

32
# create a frame for text area where summary will be displayed
33
bottom_frame = Frame(root, bg="dark grey")
34
bottom_frame.pack(side="top", fill="x", padx=10, pady=10)
35

36
# create a entry box where user can enter a keyword
37
keyword_entry = Entry(top_frame, font=("Arial", 20, "bold"), width=25, bd=4)
38
keyword_entry.pack(side="left", ipady=6)
39

40
# create a search button
41
search_button = Button(top_frame, text="Get Summary", font=(
42
    "Arial", 16, "bold"), width=15, bd=4, command=get_summary)
43
search_button.pack(side="right")
44

45
# create a scroll bar for text area
46
scroll = Scrollbar(bottom_frame)
47

48
# create a text area where summary will be displayed
49
answer = Text(bottom_frame, font=("Arial", 18), fg="black",
50
              width=55, height=20, bd=5, yscrollcommand=scroll.set)
51
answer.pack(side="left", fill="y")
52
scroll.pack(side="left", fill="y")
53

54
# start the GUI
55
root.mainloop()
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.