I am learning Python and I need to make it so that once the data is loaded, double click and the NoCotizacion
and NumeroPoliza
fields are loaded to the data
entry: EntryPolicyNumber = tk.Entry(frame_calendarios)
EntryPolicyNumber.grid(row=3, column=1, padx=10, pady=5) and EntryNroCotizacion = tk.Entry(frame_calendarios)
EntryNroCotizacion.grid(row=3, column=3, padx=0, pady=0)
To modify them. but I don't know how to create the double click function for my code.
import tkinter as tk
from tkinter import ttk
from tkcalendar import DateEntry
from tree_data import cargaDatos, obtener_fechas
def crearVentana():
global tree # Utilizar la variable global tree
ventana = tk.Tk() # Cambio aquí, crea una nueva ventana principal
ventana.title("Ventana PreFactura")
ventana.geometry("1200x700") # Establecer el tamaño de la ventana
# Obtener las dimensiones de la pantalla
screen_width = ventana.winfo_screenwidth()
screen_height = ventana.winfo_screenheight()
# Calcular la posición de la ventana para que esté centrada
window_width = 1200
window_height = 600
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
ventana.geometry(f"{window_width}x{window_height}+{x}+{y}")
frame_calendarios = tk.Frame(ventana)
frame_calendarios.pack(pady=10)
# Título centrado
titulo_label = tk.Label(frame_calendarios, text="Este es un título centrado", font=("Helvetica", 16))
titulo_label.grid(row=0, column=1, columnspan=5, pady=10)
label_inicio = tk.Label(frame_calendarios, text="Fecha Inicio")
label_inicio.grid(row=1, column=1, padx=10, pady=5)
cal_inicio = DateEntry(frame_calendarios, date_pattern='dd/mm/yyyy')
cal_inicio.grid(row=1, column=2, padx=(0,150), pady=5)
label_fin = tk.Label(frame_calendarios, text="Fecha Termino")
label_fin.grid(row=1, column=4, padx=(50,0), pady=5)
cal_fin = DateEntry(frame_calendarios, date_pattern='dd/mm/yyyy')
cal_fin.grid(row=1, column=5, padx=(0,100), pady=5)
btn_aceptar = tk.Button(frame_calendarios, text="Buscar Prefactura", command=lambda: obtener_fechas(cal_inicio, cal_fin, tree))
btn_aceptar.grid(row=2, column=1, columnspan=5, pady=10)
tree = ttk.Treeview(ventana, columns=("FechaEmision", "FechaTarificacion", "FechaSolicitud", "InicioVigencia", "NroCotizacion","NumeroPoliza", "NumeroCertificado"),
show="headings")
tree.heading("FechaEmision", text="FechaEmision")
tree.heading("FechaTarificacion", text="FechaTarificacion")
tree.heading("FechaSolicitud", text="FechaSolicitud")
tree.heading("InicioVigencia", text="InicioVigencia")
tree.heading("NroCotizacion", text="NroCotizacion")
tree.heading("NumeroPoliza", text="NumeroPoliza")
tree.heading("NumeroCertificado", text="NumeroCertificado")
tree.pack(fill="both", expand=True)
lblNumeroPoliza = tk.Label(frame_calendarios, text="Numero Poliza")
lblNumeroPoliza.grid(row=3, column=0, padx=10, pady=5)
EntryNumeroPoliza = tk.Entry(frame_calendarios)
EntryNumeroPoliza.grid(row=3, column=1, padx=10, pady=5)
lblNroCotizacion = tk.Label(frame_calendarios, text="Numero Cotizacion")
lblNroCotizacion.grid(row=3, column=2, padx=0, pady=0)
EntryNroCotizacion = tk.Entry(frame_calendarios)
EntryNroCotizacion.grid(row=3, column=3, padx=0, pady=0)
scrollbar_y = ttk.Scrollbar(ventana, orient="vertical", command=tree.yview)
scrollbar_x = ttk.Scrollbar(ventana, orient="horizontal", command=tree.xview)
tree.configure(yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
# Ajustar el Treeview al contenido de la ventana
tree.pack(fill="both", expand=True)
scrollbar_y.pack(side="right", fill="y")
scrollbar_x.pack(side="bottom", fill="x")
ventana.mainloop()