Advertisement
Najeebsk

WEB-LINKS.py

Mar 4th, 2024
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.16 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. import webbrowser
  4.  
  5. class WebUrlManager:
  6.     def __init__(self, root):
  7.         self.root = root
  8.         self.root.title("Najeeb Web URL Manager")
  9.         self.root.geometry("800x270")
  10.         self.root.configure(background="#f0ccf0")
  11.  
  12.         style = ttk.Style()
  13.         style.configure('TFrame', background='#f0f0f0')
  14.         style.configure('TLabel', background='#f0f0f0')
  15.         style.configure('TRadiobutton', background='#f0f0f0')
  16.         style.map('TRadiobutton', foreground=[('selected', 'black')])
  17.  
  18.         self.title_label = ttk.Label(root, text="Title")
  19.         self.title_label.grid(row=1, column=0, padx=10, pady=5, sticky="w")
  20.  
  21.         self.url_label = ttk.Label(root, text="URL")
  22.         self.url_label.grid(row=1, column=1, padx=10, pady=5, sticky="w")
  23.  
  24.         self.title_entry = ttk.Entry(root, width=30)
  25.         self.title_entry.grid(row=0, column=0, padx=10, pady=5, sticky="ew")
  26.  
  27.         self.url_entry = ttk.Entry(root, width=80)
  28.         self.url_entry.grid(row=0, column=1, padx=10, pady=5, sticky="ew")
  29.  
  30.         self.save_button = ttk.Button(root, text="Save", command=self.save_url)
  31.         self.save_button.grid(row=0, column=2, padx=10, pady=5, sticky="ew")
  32.  
  33.         self.title_frame = ttk.Frame(root, width=300, height=500)  # Adjust width and height as needed
  34.         self.title_frame.grid(row=2, column=0, padx=10, pady=5, sticky="nsew")
  35.         self.title_scrollbar = ttk.Scrollbar(self.title_frame, orient="vertical")
  36.         self.title_scrollbar.pack(side="right", fill="y")
  37.         self.title_listbox = tk.Listbox(self.title_frame, yscrollcommand=self.title_scrollbar.set, selectbackground="#b3d9ff", selectforeground="black")
  38.         self.title_listbox.pack(side="left", fill="both", expand=True)
  39.         self.title_scrollbar.config(command=self.title_listbox.yview)
  40.         self.title_listbox.bind("<<ListboxSelect>>", self.on_select)
  41.  
  42.         self.url_frame = ttk.Frame(root, width=600, height=500)  # Adjust width and height as needed
  43.         self.url_frame.grid(row=2, column=1, padx=10, pady=5, sticky="nsew")
  44.         self.url_scrollbar = ttk.Scrollbar(self.url_frame, orient="vertical")
  45.         self.url_scrollbar.pack(side="right", fill="y")
  46.         self.url_listbox = tk.Listbox(self.url_frame, yscrollcommand=self.url_scrollbar.set, selectbackground="#b3d9ff", selectforeground="black")
  47.         self.url_listbox.pack(side="left", fill="both", expand=True)
  48.         self.url_scrollbar.config(command=self.url_listbox.yview)
  49.         self.url_listbox.bind("<<ListboxSelect>>", self.on_select)
  50.  
  51.         self.browsers_frame = ttk.Frame(root, width=800, height=50)  # Adjust width and height as needed
  52.         self.browsers_frame.grid(row=3, columnspan=3, padx=10, pady=5, sticky="ew")
  53.         self.browser_var = tk.StringVar(value="default")
  54.         self.firefox_radio = ttk.Radiobutton(self.browsers_frame, text="Firefox", variable=self.browser_var, value="firefox", style='TRadiobutton')
  55.         self.firefox_radio.pack(side="left", padx=5)
  56.         self.chrome_radio = ttk.Radiobutton(self.browsers_frame, text="Chrome", variable=self.browser_var, value="chrome", style='TRadiobutton')
  57.         self.chrome_radio.pack(side="left", padx=5)
  58.         self.default_radio = ttk.Radiobutton(self.browsers_frame, text="Default", variable=self.browser_var, value="default", style='TRadiobutton')
  59.         self.default_radio.pack(side="left", padx=5)
  60.  
  61.         self.urls = []
  62.         self.load_urls()
  63.         self.display_urls()
  64.  
  65.     def save_url(self):
  66.         title = self.title_entry.get()
  67.         url = self.url_entry.get()
  68.  
  69.         if title and url:
  70.             self.urls.append((title, url))
  71.             self.save_to_file(title, url)
  72.             self.display_urls()
  73.  
  74.     def save_to_file(self, title, url):
  75.         with open("WEB-LINKS.txt", "a") as f:
  76.             f.write(f"{title}||{url}\n")
  77.  
  78.     def load_urls(self):
  79.         try:
  80.             with open("WEB-LINKS.txt", "r") as f:
  81.                 for line in f:
  82.                     if "||" in line:
  83.                         title, url = line.strip().split("||")
  84.                         self.urls.append((title, url))
  85.         except FileNotFoundError:
  86.             pass
  87.  
  88.     def open_url(self, url):
  89.         browser = self.browser_var.get()
  90.         if browser == "firefox":
  91.             firefox_path = r"C:\Program Files\Mozilla Firefox\firefox.exe"  # Replace with actual path
  92.             webbrowser.register('firefox', None, webbrowser.BackgroundBrowser(firefox_path))
  93.             webbrowser.get('firefox').open_new(url)
  94.         elif browser == "chrome":
  95.             webbrowser.get("chrome").open_new(url)
  96.         else:
  97.             webbrowser.open_new(url)
  98.  
  99.     def on_select(self, event):
  100.         widget = event.widget
  101.         index = widget.curselection()[0]
  102.         url = self.urls[index][1]
  103.         self.open_url(url)
  104.  
  105.     def display_urls(self):
  106.         self.title_listbox.delete(0, tk.END)
  107.         self.url_listbox.delete(0, tk.END)
  108.  
  109.         for title, url in self.urls:
  110.             self.title_listbox.insert(tk.END, title)
  111.             self.url_listbox.insert(tk.END, url)
  112.  
  113. root = tk.Tk()
  114. app = WebUrlManager(root)
  115. root.mainloop()
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement