Advertisement
MizunoBrasil

Abre Url´s (Automatização de cópia no 1fichier)

May 15th, 2024
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. # Automatização de cópia de arquivos no 1fichier. O Programa simplesmente abre as url´s inseridas na caixa de texto.
  2.  
  3. import webbrowser
  4. import threading
  5. import time
  6. import tkinter as tk
  7. from tkinter import scrolledtext, messagebox, Menu
  8.  
  9. def open_urls():
  10.     urls = text_area.get('1.0', tk.END).strip().split('\n')
  11.     if not urls:
  12.         messagebox.showinfo("Erro", "Por favor, insira pelo menos uma URL.")
  13.         return
  14.    
  15.     def open_urls_in_sequence():
  16.         for url in urls:
  17.             if url:
  18.                 webbrowser.open_new_tab(url)
  19.                 time.sleep(1)  # Pausa de 1 segundo entre aberturas de abas
  20.  
  21.     threading.Thread(target=open_urls_in_sequence).start()
  22.  
  23. def on_right_click(event):
  24.     try:
  25.         # Exibe o menu de contexto na posição do mouse
  26.         context_menu.tk_popup(event.x_root, event.y_root)
  27.     finally:
  28.         # Garante que o menu seja fechado
  29.         context_menu.grab_release()
  30.  
  31. def paste_action():
  32.     # Função para colar texto na área de texto
  33.     text_area.event_generate("<<Paste>>")
  34.  
  35. def main():
  36.     global text_area, context_menu
  37.     root = tk.Tk()
  38.     root.title("Abrir URLs - Automação de arquivos do 1fichier")
  39.  
  40.     # Configuração da janela maior e mais vertical
  41.     window_width = 500
  42.     window_height = 500
  43.     screen_width = root.winfo_screenwidth()
  44.     screen_height = root.winfo_screenheight()
  45.     x_coordinate = int((screen_width / 2) - (window_width / 2))
  46.     y_coordinate = int((screen_height / 2) - (window_height / 2))
  47.     root.geometry(f"{window_width}x{window_height}+{x_coordinate}+{y_coordinate}")
  48.  
  49.     # Área de texto maior e mais vertical para inserção de URLs
  50.     text_area = scrolledtext.ScrolledText(root, wrap=tk.WORD, height=20)
  51.     text_area.pack(padx=20, pady=10, fill=tk.BOTH, expand=True)
  52.     text_area.bind("<Button-3>", on_right_click)
  53.  
  54.     # Menu de contexto para colar
  55.     context_menu = Menu(root, tearoff=0)
  56.     context_menu.add_command(label="Colar", command=paste_action)
  57.  
  58.     # Botão para abrir URLs
  59.     button_open = tk.Button(root, text="Abrir URLs", command=open_urls)
  60.     button_open.pack(pady=20)
  61.  
  62.     root.mainloop()
  63.  
  64. if __name__ == "__main__":
  65.     main()
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement