Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox
- def generate_html():
- url = url_entry.get()
- link_text = link_text_entry.get()
- if not url or not link_text:
- messagebox.showerror("Erro", "Por favor, insira a URL de destino e o texto do link.")
- return
- html_code = f'<a href="{url}" target="_blank">{link_text}</a>'
- html_output.config(state=tk.NORMAL)
- html_output.delete('1.0', tk.END)
- html_output.insert(tk.END, html_code)
- html_output.config(state=tk.DISABLED)
- def copy_text(widget):
- widget.clipboard_clear()
- widget.clipboard_append(widget.selection_get())
- def paste_text(widget):
- widget.insert(tk.INSERT, widget.clipboard_get())
- def show_menu(event, widget):
- widget.focus_set()
- menu = tk.Menu(root, tearoff=0)
- menu.add_command(label="Copiar", command=lambda: copy_text(widget))
- menu.add_command(label="Colar", command=lambda: paste_text(widget))
- menu.tk.call("tk_popup", menu, event.x_root, event.y_root)
- # Configurando a janela
- root = tk.Tk()
- root.title("Gerador de Código HTML")
- root.geometry("500x300") # Aumentando a largura para 500 pixels
- # Centralizando a janela
- window_width = root.winfo_reqwidth()
- window_height = root.winfo_reqheight()
- position_right = int(root.winfo_screenwidth()/2 - window_width/2)
- position_down = int(root.winfo_screenheight()/2 - window_height/2)
- root.geometry("+{}+{}".format(position_right, position_down))
- # Widgets
- url_label = tk.Label(root, text="Informe a URL:")
- url_label.pack(pady=(20, 5))
- url_entry = tk.Entry(root, width=40)
- url_entry.pack(pady=5)
- url_entry.bind("<Button-3>", lambda event: show_menu(event, url_entry))
- link_text_label = tk.Label(root, text="Texto do Link:")
- link_text_label.pack()
- link_text_entry = tk.Entry(root, width=40)
- link_text_entry.pack(pady=5)
- link_text_entry.bind("<Button-3>", lambda event: show_menu(event, link_text_entry))
- generate_button = tk.Button(root, text="Gerar Código HTML", command=generate_html)
- generate_button.pack(pady=10)
- html_output = tk.Text(root, width=50, height=6, wrap=tk.WORD, state=tk.DISABLED)
- html_output.pack(pady=(0, 20))
- html_output.bind("<Button-3>", lambda event: show_menu(event, html_output))
- root.mainloop()
Add Comment
Please, Sign In to add comment