MizunoBrasil

Gerador de código html

Jun 10th, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox
  3.  
  4. def generate_html():
  5.     url = url_entry.get()
  6.     link_text = link_text_entry.get()
  7.    
  8.     if not url or not link_text:
  9.         messagebox.showerror("Erro", "Por favor, insira a URL de destino e o texto do link.")
  10.         return
  11.    
  12.     html_code = f'<a href="{url}" target="_blank">{link_text}</a>'
  13.     html_output.config(state=tk.NORMAL)
  14.     html_output.delete('1.0', tk.END)
  15.     html_output.insert(tk.END, html_code)
  16.     html_output.config(state=tk.DISABLED)
  17.  
  18. def copy_text(widget):
  19.     widget.clipboard_clear()
  20.     widget.clipboard_append(widget.selection_get())
  21.  
  22. def paste_text(widget):
  23.     widget.insert(tk.INSERT, widget.clipboard_get())
  24.  
  25. def show_menu(event, widget):
  26.     widget.focus_set()
  27.     menu = tk.Menu(root, tearoff=0)
  28.     menu.add_command(label="Copiar", command=lambda: copy_text(widget))
  29.     menu.add_command(label="Colar", command=lambda: paste_text(widget))
  30.     menu.tk.call("tk_popup", menu, event.x_root, event.y_root)
  31.  
  32. # Configurando a janela
  33. root = tk.Tk()
  34. root.title("Gerador de Código HTML")
  35. root.geometry("500x300")  # Aumentando a largura para 500 pixels
  36.  
  37. # Centralizando a janela
  38. window_width = root.winfo_reqwidth()
  39. window_height = root.winfo_reqheight()
  40. position_right = int(root.winfo_screenwidth()/2 - window_width/2)
  41. position_down = int(root.winfo_screenheight()/2 - window_height/2)
  42. root.geometry("+{}+{}".format(position_right, position_down))
  43.  
  44. # Widgets
  45. url_label = tk.Label(root, text="Informe a URL:")
  46. url_label.pack(pady=(20, 5))
  47. url_entry = tk.Entry(root, width=40)
  48. url_entry.pack(pady=5)
  49. url_entry.bind("<Button-3>", lambda event: show_menu(event, url_entry))
  50.  
  51. link_text_label = tk.Label(root, text="Texto do Link:")
  52. link_text_label.pack()
  53. link_text_entry = tk.Entry(root, width=40)
  54. link_text_entry.pack(pady=5)
  55. link_text_entry.bind("<Button-3>", lambda event: show_menu(event, link_text_entry))
  56.  
  57. generate_button = tk.Button(root, text="Gerar Código HTML", command=generate_html)
  58. generate_button.pack(pady=10)
  59.  
  60. html_output = tk.Text(root, width=50, height=6, wrap=tk.WORD, state=tk.DISABLED)
  61. html_output.pack(pady=(0, 20))
  62. html_output.bind("<Button-3>", lambda event: show_menu(event, html_output))
  63.  
  64. root.mainloop()
  65.  
Add Comment
Please, Sign In to add comment