Najeebsk

WEB-SEARCH.pyw

Jul 10th, 2025
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.61 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk, messagebox
  3. import webbrowser
  4. import os
  5.  
  6. # 20+ search engines
  7. SEARCH_ENGINES = {
  8.     "Google": "https://www.google.com/search?q=",
  9.     "Bing": "https://www.bing.com/search?q=",
  10.     "DuckDuckGo": "https://duckduckgo.com/?q=",
  11.     "YouTube": "https://www.youtube.com/results?search_query=",
  12.     "Wikipedia": "https://en.wikipedia.org/wiki/Special:Search?search=",
  13.     "Yahoo": "https://search.yahoo.com/search?p=",
  14.     "Ask": "https://www.ask.com/web?q=",
  15.     "Yandex": "https://yandex.com/search/?text=",
  16.     "Ecosia": "https://www.ecosia.org/search?q=",
  17.     "StartPage": "https://www.startpage.com/do/search?q=",
  18.     "GitHub": "https://github.com/search?q=",
  19.     "Stack Overflow": "https://stackoverflow.com/search?q=",
  20.     "Reddit": "https://www.reddit.com/search/?q=",
  21.     "Amazon": "https://www.amazon.com/s?k=",
  22.     "eBay": "https://www.ebay.com/sch/i.html?_nkw=",
  23.     "Quora": "https://www.quora.com/search?q=",
  24.     "Twitter": "https://twitter.com/search?q=",
  25.     "Facebook": "https://www.facebook.com/search/top?q=",
  26.     "LinkedIn": "https://www.linkedin.com/search/results/all/?keywords=",
  27.     "Pinterest": "https://www.pinterest.com/search/pins/?q=",
  28. }
  29.  
  30. # Advanced search templates
  31. ADVANCED_TEMPLATES = {
  32.     'Index of movies': 'intitle:"index of" (mp4|mkv|avi) -html -htm -php -asp -jsp',
  33.     'Search in site (.gov.pk)': 'site:gov.pk',
  34.     'Search Excel files': 'filetype:xls',
  35.     'Public webcam pages': 'inurl:view.shtml',
  36.     'IP camera pages': 'inurl:/view/index.shtml',
  37.     'Wildcard login': '"login * gmail"',
  38.     'Exclude -youtube': 'download song -youtube',
  39.     'OR example': 'song mp3 OR wav',
  40. }
  41.  
  42. def perform_search():
  43.     engine = engine_var.get()
  44.     browser = browser_var.get()
  45.     query = entry_query.get()
  46.  
  47.     if not query:
  48.         messagebox.showwarning("Empty Search", "Please enter a search query.")
  49.         return
  50.  
  51.     search_url = SEARCH_ENGINES.get(engine, "") + query.replace(" ", "+")
  52.  
  53.     try:
  54.         if browser == "System Default":
  55.             webbrowser.open(search_url)
  56.  
  57.         elif browser == "Firefox":
  58.             firefox_paths = [
  59.                 r"C:\Program Files\Mozilla Firefox\firefox.exe",
  60.                 r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
  61.             ]
  62.             for path in firefox_paths:
  63.                 if os.path.exists(path):
  64.                     webbrowser.register('firefox', None, webbrowser.BackgroundBrowser(path))
  65.                     webbrowser.get('firefox').open(search_url)
  66.                     return
  67.             messagebox.showerror("Browser Not Found", "Firefox not found on this system.")
  68.  
  69.         elif browser == "Chrome":
  70.             chrome_paths = [
  71.                 r"C:\Program Files\Google\Chrome\Application\chrome.exe",
  72.                 r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
  73.             ]
  74.             for path in chrome_paths:
  75.                 if os.path.exists(path):
  76.                     webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(path))
  77.                     webbrowser.get('chrome').open(search_url)
  78.                     return
  79.             messagebox.showerror("Browser Not Found", "Chrome not found on this system.")
  80.  
  81.         else:
  82.             messagebox.showwarning("Browser Error", f"{browser} is not supported.")
  83.     except Exception as e:
  84.         messagebox.showerror("Error", f"Failed to open browser:\n{str(e)}")
  85.  
  86. def insert_template(event=None):
  87.     selected = template_var.get()
  88.     if selected in ADVANCED_TEMPLATES:
  89.         entry_query.delete(0, tk.END)
  90.         entry_query.insert(0, ADVANCED_TEMPLATES[selected])
  91.  
  92. # GUI
  93. root = tk.Tk()
  94. root.title("Najeeb All-in-One Search Engine GUI (Advanced Mode)")
  95. root.geometry("750x300")
  96. root.resizable(False, False)
  97.  
  98. style = ttk.Style(root)
  99. style.configure("TFrame", background="#f9f9f9")
  100. style.configure("TButton", font=("Segoe UI", 10, "bold"))
  101. style.configure("TLabel", background="#f9f9f9", font=("Segoe UI", 10))
  102. style.configure("TEntry", font=("Segoe UI", 10))
  103. style.configure("TCombobox", font=("Segoe UI", 10))
  104.  
  105. main_frame = ttk.Frame(root, padding=15)
  106. main_frame.pack(fill=tk.BOTH, expand=True)
  107.  
  108. # Search engine selector
  109. ttk.Label(main_frame, text="🌍 Select Search Engine:").grid(row=0, column=0, sticky="w", padx=5, pady=5)
  110. engine_var = tk.StringVar(value="Google")
  111. engine_cb = ttk.Combobox(main_frame, textvariable=engine_var, values=list(SEARCH_ENGINES.keys()), width=35, state="readonly")
  112. engine_cb.grid(row=0, column=1, padx=5, pady=5)
  113.  
  114. # Browser selector
  115. ttk.Label(main_frame, text="🧭 Open With Browser:").grid(row=1, column=0, sticky="w", padx=5, pady=5)
  116. browser_var = tk.StringVar(value="System Default")
  117. browser_cb = ttk.Combobox(main_frame, textvariable=browser_var, values=["System Default", "Firefox", "Chrome"], width=35, state="readonly")
  118. browser_cb.grid(row=1, column=1, padx=5, pady=5)
  119.  
  120. # Template dropdown
  121. ttk.Label(main_frame, text="🎯 Search Template:").grid(row=2, column=0, sticky="w", padx=5, pady=5)
  122. template_var = tk.StringVar()
  123. template_cb = ttk.Combobox(main_frame, textvariable=template_var, values=list(ADVANCED_TEMPLATES.keys()), width=35, state="readonly")
  124. template_cb.grid(row=2, column=1, padx=5, pady=5)
  125. template_cb.bind("<<ComboboxSelected>>", insert_template)
  126.  
  127. # Query entry
  128. ttk.Label(main_frame, text="📝 Search Query:").grid(row=3, column=0, sticky="w", padx=5, pady=5)
  129. entry_query = ttk.Entry(main_frame, width=60)
  130. entry_query.grid(row=3, column=1, padx=5, pady=5)
  131.  
  132. # Search button
  133. ttk.Button(main_frame, text="🔍 Search Now", command=perform_search).grid(row=4, column=1, sticky="e", padx=5, pady=15)
  134.  
  135. root.mainloop()
  136.  
Advertisement
Add Comment
Please, Sign In to add comment