Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk
- import webbrowser
- class WebUrlManager:
- def __init__(self, root):
- self.root = root
- self.root.title("Najeeb Web URL Manager")
- self.root.geometry("800x270")
- self.root.configure(background="#f0ccf0")
- style = ttk.Style()
- style.configure('TFrame', background='#f0f0f0')
- style.configure('TLabel', background='#f0f0f0')
- style.configure('TRadiobutton', background='#f0f0f0')
- style.map('TRadiobutton', foreground=[('selected', 'black')])
- self.title_label = ttk.Label(root, text="Title")
- self.title_label.grid(row=1, column=0, padx=10, pady=5, sticky="w")
- self.url_label = ttk.Label(root, text="URL")
- self.url_label.grid(row=1, column=1, padx=10, pady=5, sticky="w")
- self.title_entry = ttk.Entry(root, width=30)
- self.title_entry.grid(row=0, column=0, padx=10, pady=5, sticky="ew")
- self.url_entry = ttk.Entry(root, width=80)
- self.url_entry.grid(row=0, column=1, padx=10, pady=5, sticky="ew")
- self.save_button = ttk.Button(root, text="Save", command=self.save_url)
- self.save_button.grid(row=0, column=2, padx=10, pady=5, sticky="ew")
- self.title_frame = ttk.Frame(root, width=300, height=500) # Adjust width and height as needed
- self.title_frame.grid(row=2, column=0, padx=10, pady=5, sticky="nsew")
- self.title_scrollbar = ttk.Scrollbar(self.title_frame, orient="vertical")
- self.title_scrollbar.pack(side="right", fill="y")
- self.title_listbox = tk.Listbox(self.title_frame, yscrollcommand=self.on_vertical_scroll, selectbackground="#b3d9ff", selectforeground="black")
- self.title_listbox.pack(side="left", fill="both", expand=True)
- self.title_scrollbar.config(command=self.on_vertical_scroll)
- self.title_listbox.bind("<<ListboxSelect>>", self.on_select)
- self.url_frame = ttk.Frame(root, width=600, height=500) # Adjust width and height as needed
- self.url_frame.grid(row=2, column=1, padx=10, pady=5, sticky="nsew")
- self.url_scrollbar = ttk.Scrollbar(self.url_frame, orient="vertical")
- self.url_scrollbar.pack(side="right", fill="y")
- self.url_listbox = tk.Listbox(self.url_frame, yscrollcommand=self.on_vertical_scroll, selectbackground="#b3d9ff", selectforeground="black")
- self.url_listbox.pack(side="left", fill="both", expand=True)
- self.url_scrollbar.config(command=self.on_vertical_scroll)
- self.browsers_frame = ttk.Frame(root, width=800, height=50) # Adjust width and height as needed
- self.browsers_frame.grid(row=3, columnspan=3, padx=10, pady=5, sticky="ew")
- self.browser_var = tk.StringVar(value="default")
- self.firefox_radio = ttk.Radiobutton(self.browsers_frame, text="Firefox", variable=self.browser_var, value="firefox", style='TRadiobutton')
- self.firefox_radio.pack(side="left", padx=5)
- self.chrome_radio = ttk.Radiobutton(self.browsers_frame, text="Chrome", variable=self.browser_var, value="chrome", style='TRadiobutton')
- self.chrome_radio.pack(side="left", padx=5)
- self.default_radio = ttk.Radiobutton(self.browsers_frame, text="Default", variable=self.browser_var, value="default", style='TRadiobutton')
- self.default_radio.pack(side="left", padx=5)
- self.urls = []
- self.load_urls()
- self.display_urls()
- def save_url(self):
- title = self.title_entry.get()
- url = self.url_entry.get()
- if title and url:
- self.urls.append((title, url))
- self.save_to_file(title, url)
- self.display_urls()
- def save_to_file(self, title, url):
- with open("WEB-LINKS.txt", "a") as f:
- f.write(f"{title}||{url}\n")
- def load_urls(self):
- try:
- with open("WEB-LINKS.txt", "r") as f:
- for line in f:
- if "||" in line:
- title, url = line.strip().split("||")
- self.urls.append((title, url))
- except FileNotFoundError:
- pass
- def open_url(self, url):
- browser = self.browser_var.get()
- if browser == "firefox":
- firefox_path = r"C:\Program Files\Mozilla Firefox\firefox.exe" # Replace with actual path
- webbrowser.register('firefox', None, webbrowser.BackgroundBrowser(firefox_path))
- webbrowser.get('firefox').open_new(url)
- elif browser == "chrome":
- webbrowser.get("chrome").open_new(url)
- else:
- webbrowser.open_new(url)
- def on_select(self, event):
- widget = event.widget
- index = widget.curselection()[0]
- url = self.urls[index][1]
- self.open_url(url)
- def on_vertical_scroll(self, *args):
- if args[0] == "moveto":
- self.title_listbox.yview_moveto(args[1])
- self.url_listbox.yview_moveto(args[1])
- elif args[0] == "scroll":
- self.title_listbox.yview_scroll(int(args[1]), "units")
- self.url_listbox.yview_scroll(int(args[1]), "units")
- def display_urls(self):
- self.title_listbox.delete(0, tk.END)
- self.url_listbox.delete(0, tk.END)
- for title, url in self.urls:
- self.title_listbox.insert(tk.END, title)
- self.url_listbox.insert(tk.END, url)
- root = tk.Tk()
- app = WebUrlManager(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement