Google Search with Python 3 and Tkinter

Monday, 8 February 2010, 36,923

Google Search with Python and Tkinter;

# http://m-eken.com
# python 3
#google Searcher
import tkinter,urllib.request,urllib.parse,urllib.error
from tkinter import *
from tkinter import ttk

class window:
    def __init__(self,root):
        self.root=root
        self.root.title("Google Searcher")
        ttk.Frame(self.root, width=500,height=250).pack()
        self.init_widgets()

    def init_widgets(self):
        ttk.Button(self.root, command=self.insert_text,text="Gooo",width="10").place(x=400,y=10)
        self.txt=tkinter.Text(self.root,width="52",height="10", font=12)
        self.txt.place(x=10,y=40)
        self.searchWord=tkinter.Text(self.root,width="42",height="1", font=12)
        self.searchWord.insert(tkinter.INSERT,"google search with python 3 tkinter")
        self.searchWord.place(x=10,y=15)
 

    def insert_text(self):
        GWord=self.searchWord.get(1.0,END)
        url="http://www.google.com/search?hl=en&q="+"+".join(GWord.split())
        req=urllib.request.Request(url)
        req.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13")
        GWord= urllib.request.urlopen(req).read()
        self.txt.insert(tkinter.INSERT,  GWord)
         

if __name__=="__main__":
    root=tkinter.Tk()
    window(root)
    root.mainloop()

Leave a comment
Name(required)
Mail (will not be publishing) (required)
Website