Wikipedia GUI using python

How to Get Wikipedia Results Using Python (GUI)

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)

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():
        query = entry1.get()
        result = wikipedia.summary(query)
        text1.insert(tk.END, result)
        showerror("Error","Someting went wrong")

lable1 = ttk.Label(win,text="Query")

entry1 = ttk.Entry(win,width=40)

button1 = ttk.Button(win,text="Search",command=search)

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


You can see the output here:

Post you may like: Rock Paper Scissors Game Using Python

Leave a Reply

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

You May Also Like