4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Wikipedia search tool.

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')

<br>
Here I named the application "Wikipedia Search Tool". <br>

#### <center>Defining the search_me function</center><br>

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.')
<br>

#### <center>Search box, Button and Text Box</center><br>

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()

<br>

### <center>So the full code is here</center>
<br>

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()

<br>



# <center>Thank You</center>
32 upvotes 1 downvotes $5.30

Replies (4)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: