Prerequisite:
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications.
Wikipedia is a Python library that makes it easy to access and parse data from “wikipedia.org”. Here, we are using summary function of this module to get the summary of the argument(as a string) given to the program.
Installation
To install the Wikipedia library, just type this in terminal :
pip install wikipedia
Approach
- Import module
- Create a normal window
- Add buttons
- Create mechanism to scrap summary from wikipedia
- Display summary
- Execute code
Program:
Python3
from tkinter import Tk, Frame, Toplevel, Entry, Button, Text, Scrollbar, END, INSERTfrom tkinter.messagebox import showerrorfrom wikipedia import summary # create function which will show summarydef get_summary(): # if summary will be fetch from internet try: # clear text area answer.delete(1.0, END) # show summary in text area answer.insert(INSERT, summary(keyword_entry.get())) # if any it will give error, it will be shown in a new error window except Exception as error: # Title of new error window is "Error" and message will be # string given in variable error showerror("Error", error) # create a GUI windowroot = Tk() # set title of windowroot.title("Wikipedia Summary") # set geometry of geometryroot.geometry("770x650") # set window's width and height to # false => window will not be resizableroot.resizable(False, False) # set background colour of windowroot.configure(bg="dark grey") # create a frame for entry and buttontop_frame = Frame(root, bg="dark grey")top_frame.pack(side="top", fill="x", padx=50, pady=10) # create a frame for text area where summary will be displayedbottom_frame = Frame(root, bg="dark grey")bottom_frame.pack(side="top", fill="x", padx=10, pady=10) # create a entry box where user can enter a keywordkeyword_entry = Entry(top_frame, font=("Arial", 20, "bold"), width=25, bd=4)keyword_entry.pack(side="left", ipady=6) # create a search buttonsearch_button = Button(top_frame, text="SEARCH", font=( "Arial", 18, "bold"), width=15, bd=4, command=get_summary)search_button.pack(side="right") # create a scroll bar for text areascroll = Scrollbar(bottom_frame) # create a text area where summary will be displayedanswer = Text(bottom_frame, font=("Arial", 18), fg="red", width=55, height=20, bd=5, yscrollcommand=scroll.set)answer.pack(side="left", fill="y")scroll.pack(side="left", fill="y") # start the GUIroot.mainloop() |
Output :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


