Advertisement
MizunoBrasil

Agenda de Contatos

Jun 17th, 2023 (edited)
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.53 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. import random
  4. import webbrowser
  5.  
  6. # Dados aleatórios de exemplo
  7. dados = [
  8.     {'Nome': 'João da Silva', 'Telefone/WhatsApp': '5531976543210', 'E-mail': 'joao.silva@example.com'},
  9.     {'Nome': 'Ana Souza', 'Telefone/WhatsApp': '5531987654321', 'E-mail': 'ana.souza@example.com'},
  10.     {'Nome': 'Carlos Pereira', 'Telefone/WhatsApp': '5531965432109', 'E-mail': 'carlos.pereira@example.com'},
  11.     {'Nome': 'Maria Santos', 'Telefone/WhatsApp': '5531954321098', 'E-mail': 'maria.santos@example.com'},
  12.     {'Nome': 'Pedro Oliveira', 'Telefone/WhatsApp': '5531943210987', 'E-mail': 'pedro.oliveira@example.com'},
  13.     {'Nome': 'Lúcia Mendes', 'Telefone/WhatsApp': '5531932109876', 'E-mail': 'lucia.mendes@example.com'},
  14.     {'Nome': 'Fernando Costa', 'Telefone/WhatsApp': '5531921098765', 'E-mail': 'fernando.costa@example.com'},
  15.     {'Nome': 'Mariana Almeida', 'Telefone/WhatsApp': '5531910987654', 'E-mail': 'mariana.almeida@example.com'},
  16.     {'Nome': 'Ricardo Ferreira', 'Telefone/WhatsApp': '5531909876543', 'E-mail': 'ricardo.ferreira@example.com'},
  17.     {'Nome': 'Camila Ramos', 'Telefone/WhatsApp': '5531998765432', 'E-mail': 'camila.ramos@example.com'},
  18.     {'Nome': 'Paulo Sousa', 'Telefone/WhatsApp': '5531976543210', 'E-mail': 'paulo.sousa@example.com'},
  19.     {'Nome': 'Fernanda Silva', 'Telefone/WhatsApp': '5531987654321', 'E-mail': 'fernanda.silva@example.com'},
  20.     {'Nome': 'Roberto Pereira', 'Telefone/WhatsApp': '5531965432109', 'E-mail': 'roberto.pereira@example.com'},
  21.     {'Nome': 'Laura Santos', 'Telefone/WhatsApp': '5531954321098', 'E-mail': 'laura.santos@example.com'},
  22.     {'Nome': 'Gabriel Oliveira', 'Telefone/WhatsApp': '5531943210987', 'E-mail': 'gabriel.oliveira@example.com'},
  23.     {'Nome': 'Sofia Mendes', 'Telefone/WhatsApp': '5531932109876', 'E-mail': 'sofia.mendes@example.com'},
  24.     {'Nome': 'Hugo Costa', 'Telefone/WhatsApp': '5531921098765', 'E-mail': 'hugo.costa@example.com'},
  25.     {'Nome': 'Carolina Almeida', 'Telefone/WhatsApp': '5531910987654', 'E-mail': 'carolina.almeida@example.com'},
  26.     {'Nome': 'Gustavo Ferreira', 'Telefone/WhatsApp': '5531909876543', 'E-mail': 'gustavo.ferreira@example.com'},
  27.     {'Nome': 'Amanda Ramos', 'Telefone/WhatsApp': '5531998765432', 'E-mail': 'amanda.ramos@example.com'}  
  28. ]
  29.  
  30. def abrir_link_whatsapp(telefone):
  31.     link = f"https://api.whatsapp.com/send?phone={telefone}"
  32.     webbrowser.open(link)
  33.  
  34. def abrir_menu_contexto(event):
  35.     item_selecionado = tree.identify_row(event.y)
  36.     if item_selecionado:
  37.         telefone = tree.item(item_selecionado)['values'][1]
  38.         menu_contexto.tk_popup(event.x_root, event.y_root)
  39.         menu_contexto.entryconfigure('Enviar mensagem no WhatsApp', command=lambda: abrir_link_whatsapp(telefone))
  40.  
  41. # Criar janela principal
  42. root = tk.Tk()
  43. root.title("Lista de Contatos")
  44.  
  45. # Define a largura e altura da janela
  46. largura = 1200
  47. altura = 400
  48.  
  49. # Calcula as coordenadas para centralizar a janela
  50. largura_tela = root.winfo_screenwidth()
  51. altura_tela = root.winfo_screenheight()
  52. x = (largura_tela - largura) // 2
  53. y = (altura_tela - altura) // 2
  54.  
  55. # Define a geometria da janela com as coordenadas centralizadas
  56. root.geometry(f"{largura}x{altura}+{x}+{y}")
  57.  
  58. # Criar Treeview
  59. tree = ttk.Treeview(root, columns=('Nome', 'Telefone/WhatsApp', 'E-mail'), show='headings')
  60. tree.heading('Nome', text='Nome')
  61. tree.heading('Telefone/WhatsApp', text='Telefone/WhatsApp')
  62. tree.heading('E-mail', text='E-mail')
  63.  
  64. # Ajustar a largura das colunas
  65. tree.column('Nome', width=int(largura * 0.4))  # Largura da coluna 'Nome'
  66. tree.column('Telefone/WhatsApp', width=int(largura * 0.3))  # Largura da coluna 'Telefone/WhatsApp'
  67. tree.column('E-mail', width=int(largura * 0.3))  # Largura da coluna 'E-mail'
  68.  
  69. # Adicionar dados à Treeview
  70. for contato in dados:
  71.     nome = contato['Nome']
  72.     telefone = contato['Telefone/WhatsApp']
  73.     email = contato['E-mail']
  74.     tree.insert('', 'end', values=(nome, telefone, email))
  75.  
  76. # Criar barra de rolagem
  77. scrollbar = ttk.Scrollbar(root, orient=tk.VERTICAL, command=tree.yview)
  78. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  79.  
  80. # Vincular a barra de rolagem à Treeview
  81. tree.configure(yscrollcommand=scrollbar.set)
  82.  
  83. # Posicionar a TreeView
  84. tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  85.  
  86. # Criar menu de contexto
  87. menu_contexto = tk.Menu(root, tearoff=0)
  88. menu_contexto.add_command(label='Enviar mensagem no WhatsApp')
  89.  
  90. # Associar o evento de clique com botão direito do mouse ao abrir o menu de contexto
  91. tree.bind('<Button-3>', abrir_menu_contexto)
  92.  
  93. # Iniciar aplicativo
  94. root.mainloop()
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement