Wikipedia GUI using python

How to Get Wikipedia Results Using Python (GUI)

Spread the love

In this tutorial I’ll show you how to get Wikipedia results using python. This will be a GUI.

To get results from wikipedia using python we need to use one module named “wikipedia”. To install this module, open terminal and type,

pip install wikipedia

You can also read it’s documentation from here.

Get data from Wikipedia is quite simple using python. we have to just use summary function of Wikipedia module. Just like this,

import wikipedia

query = "Python Programming Language"
result = wikipedia.summary(query)
print(result)

If we run this above code, we’ll get this result, shown in below image.

Get Wikipedia Results Using Python - papa programmer

Now we are able to get data from Wikipedia. so, now let’s convert this script into GUI.

Here we’ll use another module called Tkinter to make GUIs.

Helpful Blog: GUI Programming With Python

Here is the complete code.

import tkinter as tk
import tkinter.ttk as ttk
from tkinter.messagebox import showerror
import wikipedia

win = tk.Tk()
win.title("Wikipedia GUI")

def search():
    try:
        query = entry1.get()
        result = wikipedia.summary(query)
        text1.insert(tk.END, result)
    except:
        showerror("Error","Someting went wrong")

lable1 = ttk.Label(win,text="Query")
lable1.grid(row=0,column=0)

entry1 = ttk.Entry(win,width=40)
entry1.grid(row=0,column=1,padx=1)

button1 = ttk.Button(win,text="Search",command=search)
button1.grid(row=0,column=2,padx=5)

text1 = tk.Text(win,width=50)
text1.grid(row=1, column=0, columnspan=3)

win.mainloop()

You can see the output here:

Post you may like: Rock Paper Scissors Game Using Python


Spread the love
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like