Wikipedia search tool.

avatar

Previously I posted a simple GUI application that I made with python and tkinter module of python. I made another GUI which is a Wikipedia search tool. That means it has a search box , a search button and a text area. Let's jump to the codes.

Importing, naming and sizing


import tkinter as tk
import wikipedia


win  = tk.Tk()
win.geometry('480x360')
win.resizable(0,0)
win.title('Wikipedia Search Tool')



Here I named the application "Wikipedia Search Tool".

Defining the search_me function

def search_me():
    entry_text = entry1.get()
    text_box.delete(1.0, tk.END)
    try:
        answer = wikipedia.summary(entry_text)

        text_box.insert(tk.INSERT, answer)
    except:
        text_box.insert(tk.INSERT, f'Nothing found with {entry_text} or check your internet connection.')


Search box, Button and Text Box

top_frame = tk.Frame(win)
top_frame.pack(pady=10)
entry1 = tk.Entry(top_frame, width=30)
entry1.pack()
search_btn = tk.Button(top_frame, text='Search', command = search_me)
search_btn.pack(pady=4)

bottom_frame = tk.Frame(win)
bottom_frame.pack()

scroll_bar = tk.Scrollbar(bottom_frame, )
scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
text_box = tk.Text(bottom_frame, width=80, height = 30, wrap='word', yscrollcommand= scroll_bar.set)
scroll_bar.config(command=text_box.yview)
text_box.pack(side=tk.LEFT, padx=8, pady=8)



win.mainloop()


So the full code is here


import tkinter as tk
import wikipedia


win  = tk.Tk()
win.geometry('480x360')
win.resizable(0,0)
win.title('Wikipedia Search Tool')

def search_me():
    entry_text = entry1.get()
    text_box.delete(1.0, tk.END)
    try:
        answer = wikipedia.summary(entry_text)

        text_box.insert(tk.INSERT, answer)
    except:
        text_box.insert(tk.INSERT, f'Nothing found with {entry_text} or check your internet connection.')


top_frame = tk.Frame(win)
top_frame.pack(pady=10)
entry1 = tk.Entry(top_frame, width=30)
entry1.pack()
search_btn = tk.Button(top_frame, text='Search', command = search_me)
search_btn.pack(pady=4)

bottom_frame = tk.Frame(win)
bottom_frame.pack()

scroll_bar = tk.Scrollbar(bottom_frame, )
scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
text_box = tk.Text(bottom_frame, width=80, height = 30, wrap='word', yscrollcommand= scroll_bar.set)
scroll_bar.config(command=text_box.yview)
text_box.pack(side=tk.LEFT, padx=8, pady=8)



win.mainloop()


Thank You



0
0
0.000
4 comments
avatar

Congratulations @sksksk! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 100 upvotes.
Your next target is to reach 200 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Support the HiveBuzz project. Vote for our proposal!
0
0
0.000