Advertisement
Najeebsk

WEB-LINKS2.py

Mar 4th, 2024
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.43 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.on_vertical_scroll, selectbackground="#b3d9ff", selectforeground="black")
  38.         self.title_listbox.pack(side="left", fill="both", expand=True)
  39.         self.title_scrollbar.config(command=self.on_vertical_scroll)
  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.on_vertical_scroll, selectbackground="#b3d9ff", selectforeground="black")
  47.         self.url_listbox.pack(side="left", fill="both", expand=True)
  48.         self.url_scrollbar.config(command=self.on_vertical_scroll)
  49.  
  50.         self.browsers_frame = ttk.Frame(root, width=800, height=50)  # Adjust width and height as needed
  51.         self.browsers_frame.grid(row=3, columnspan=3, padx=10, pady=5, sticky="ew")
  52.         self.browser_var = tk.StringVar(value="default")
  53.         self.firefox_radio = ttk.Radiobutton(self.browsers_frame, text="Firefox", variable=self.browser_var, value="firefox", style='TRadiobutton')
  54.         self.firefox_radio.pack(side="left", padx=5)
  55.         self.chrome_radio = ttk.Radiobutton(self.browsers_frame, text="Chrome", variable=self.browser_var, value="chrome", style='TRadiobutton')
  56.         self.chrome_radio.pack(side="left", padx=5)
  57.         self.default_radio = ttk.Radiobutton(self.browsers_frame, text="Default", variable=self.browser_var, value="default", style='TRadiobutton')
  58.         self.default_radio.pack(side="left", padx=5)
  59.  
  60.         self.urls = []
  61.         self.load_urls()
  62.         self.display_urls()
  63.  
  64.     def save_url(self):
  65.         title = self.title_entry.get()
  66.         url = self.url_entry.get()
  67.  
  68.         if title and url:
  69.             self.urls.append((title, url))
  70.             self.save_to_file(title, url)
  71.             self.display_urls()
  72.  
  73.     def save_to_file(self, title, url):
  74.         with open("WEB-LINKS.txt", "a") as f:
  75.             f.write(f"{title}||{url}\n")
  76.  
  77.     def load_urls(self):
  78.         try:
  79.             with open("WEB-LINKS.txt", "r") as f:
  80.                 for line in f:
  81.                     if "||" in line:
  82.                         title, url = line.strip().split("||")
  83.                         self.urls.append((title, url))
  84.         except FileNotFoundError:
  85.             pass
  86.  
  87.     def open_url(self, url):
  88.         browser = self.browser_var.get()
  89.         if browser == "firefox":
  90.             firefox_path = r"C:\Program Files\Mozilla Firefox\firefox.exe"  # Replace with actual path
  91.             webbrowser.register('firefox', None, webbrowser.BackgroundBrowser(firefox_path))
  92.             webbrowser.get('firefox').open_new(url)
  93.         elif browser == "chrome":
  94.             webbrowser.get("chrome").open_new(url)
  95.         else:
  96.             webbrowser.open_new(url)
  97.  
  98.     def on_select(self, event):
  99.         widget = event.widget
  100.         index = widget.curselection()[0]
  101.         url = self.urls[index][1]
  102.         self.open_url(url)
  103.  
  104.     def on_vertical_scroll(self, *args):
  105.         if args[0] == "moveto":
  106.             self.title_listbox.yview_moveto(args[1])
  107.             self.url_listbox.yview_moveto(args[1])
  108.         elif args[0] == "scroll":
  109.             self.title_listbox.yview_scroll(int(args[1]), "units")
  110.             self.url_listbox.yview_scroll(int(args[1]), "units")
  111.  
  112.     def display_urls(self):
  113.         self.title_listbox.delete(0, tk.END)
  114.         self.url_listbox.delete(0, tk.END)
  115.  
  116.         for title, url in self.urls:
  117.             self.title_listbox.insert(tk.END, title)
  118.             self.url_listbox.insert(tk.END, url)
  119.  
  120. root = tk.Tk()
  121. app = WebUrlManager(root)
  122. root.mainloop()
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement