Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk, messagebox
- import webbrowser
- import os
- # 20+ search engines
- SEARCH_ENGINES = {
- "Google": "https://www.google.com/search?q=",
- "Bing": "https://www.bing.com/search?q=",
- "DuckDuckGo": "https://duckduckgo.com/?q=",
- "YouTube": "https://www.youtube.com/results?search_query=",
- "Wikipedia": "https://en.wikipedia.org/wiki/Special:Search?search=",
- "Yahoo": "https://search.yahoo.com/search?p=",
- "Ask": "https://www.ask.com/web?q=",
- "Yandex": "https://yandex.com/search/?text=",
- "Ecosia": "https://www.ecosia.org/search?q=",
- "StartPage": "https://www.startpage.com/do/search?q=",
- "GitHub": "https://github.com/search?q=",
- "Stack Overflow": "https://stackoverflow.com/search?q=",
- "Reddit": "https://www.reddit.com/search/?q=",
- "Amazon": "https://www.amazon.com/s?k=",
- "eBay": "https://www.ebay.com/sch/i.html?_nkw=",
- "Quora": "https://www.quora.com/search?q=",
- "Twitter": "https://twitter.com/search?q=",
- "Facebook": "https://www.facebook.com/search/top?q=",
- "LinkedIn": "https://www.linkedin.com/search/results/all/?keywords=",
- "Pinterest": "https://www.pinterest.com/search/pins/?q=",
- }
- # Advanced search templates
- ADVANCED_TEMPLATES = {
- 'Index of movies': 'intitle:"index of" (mp4|mkv|avi) -html -htm -php -asp -jsp',
- 'Search in site (.gov.pk)': 'site:gov.pk',
- 'Search Excel files': 'filetype:xls',
- 'Public webcam pages': 'inurl:view.shtml',
- 'IP camera pages': 'inurl:/view/index.shtml',
- 'Wildcard login': '"login * gmail"',
- 'Exclude -youtube': 'download song -youtube',
- 'OR example': 'song mp3 OR wav',
- }
- def perform_search():
- engine = engine_var.get()
- browser = browser_var.get()
- query = entry_query.get()
- if not query:
- messagebox.showwarning("Empty Search", "Please enter a search query.")
- return
- search_url = SEARCH_ENGINES.get(engine, "") + query.replace(" ", "+")
- try:
- if browser == "System Default":
- webbrowser.open(search_url)
- elif browser == "Firefox":
- firefox_paths = [
- r"C:\Program Files\Mozilla Firefox\firefox.exe",
- r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
- ]
- for path in firefox_paths:
- if os.path.exists(path):
- webbrowser.register('firefox', None, webbrowser.BackgroundBrowser(path))
- webbrowser.get('firefox').open(search_url)
- return
- messagebox.showerror("Browser Not Found", "Firefox not found on this system.")
- elif browser == "Chrome":
- chrome_paths = [
- r"C:\Program Files\Google\Chrome\Application\chrome.exe",
- r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
- ]
- for path in chrome_paths:
- if os.path.exists(path):
- webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(path))
- webbrowser.get('chrome').open(search_url)
- return
- messagebox.showerror("Browser Not Found", "Chrome not found on this system.")
- else:
- messagebox.showwarning("Browser Error", f"{browser} is not supported.")
- except Exception as e:
- messagebox.showerror("Error", f"Failed to open browser:\n{str(e)}")
- def insert_template(event=None):
- selected = template_var.get()
- if selected in ADVANCED_TEMPLATES:
- entry_query.delete(0, tk.END)
- entry_query.insert(0, ADVANCED_TEMPLATES[selected])
- # GUI
- root = tk.Tk()
- root.title("Najeeb All-in-One Search Engine GUI (Advanced Mode)")
- root.geometry("750x300")
- root.resizable(False, False)
- style = ttk.Style(root)
- style.configure("TFrame", background="#f9f9f9")
- style.configure("TButton", font=("Segoe UI", 10, "bold"))
- style.configure("TLabel", background="#f9f9f9", font=("Segoe UI", 10))
- style.configure("TEntry", font=("Segoe UI", 10))
- style.configure("TCombobox", font=("Segoe UI", 10))
- main_frame = ttk.Frame(root, padding=15)
- main_frame.pack(fill=tk.BOTH, expand=True)
- # Search engine selector
- ttk.Label(main_frame, text="🌍 Select Search Engine:").grid(row=0, column=0, sticky="w", padx=5, pady=5)
- engine_var = tk.StringVar(value="Google")
- engine_cb = ttk.Combobox(main_frame, textvariable=engine_var, values=list(SEARCH_ENGINES.keys()), width=35, state="readonly")
- engine_cb.grid(row=0, column=1, padx=5, pady=5)
- # Browser selector
- ttk.Label(main_frame, text="🧭 Open With Browser:").grid(row=1, column=0, sticky="w", padx=5, pady=5)
- browser_var = tk.StringVar(value="System Default")
- browser_cb = ttk.Combobox(main_frame, textvariable=browser_var, values=["System Default", "Firefox", "Chrome"], width=35, state="readonly")
- browser_cb.grid(row=1, column=1, padx=5, pady=5)
- # Template dropdown
- ttk.Label(main_frame, text="🎯 Search Template:").grid(row=2, column=0, sticky="w", padx=5, pady=5)
- template_var = tk.StringVar()
- template_cb = ttk.Combobox(main_frame, textvariable=template_var, values=list(ADVANCED_TEMPLATES.keys()), width=35, state="readonly")
- template_cb.grid(row=2, column=1, padx=5, pady=5)
- template_cb.bind("<<ComboboxSelected>>", insert_template)
- # Query entry
- ttk.Label(main_frame, text="📝 Search Query:").grid(row=3, column=0, sticky="w", padx=5, pady=5)
- entry_query = ttk.Entry(main_frame, width=60)
- entry_query.grid(row=3, column=1, padx=5, pady=5)
- # Search button
- ttk.Button(main_frame, text="🔍 Search Now", command=perform_search).grid(row=4, column=1, sticky="e", padx=5, pady=15)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment