A
Anonymous

User Registration - Copy this React, Tailwind Component to your project

Import tkinter as tk import customtkinter as ctk from tkinter import messagebox, ttk from pymongo import MongoClient from datetime import datetime # Conexión a la base de datos MongoDB def conectar_db(): try: client = MongoClient('mongodb://localhost:27017/') db = client['Pallet'] collection = db['movimientos_materia_prima'] return collection except Exception as e: messagebox.showerror("Error de Conexión", f"No se pudo conectar a la base de datos: {e}") exit() # Función para registrar un movimiento def registrar_movimiento(): insumo = insumo_entry.get().strip() estado = estado_combobox.get().strip() ubicacion = ubicacion_combobox.get().strip() fecha = fecha_entry.get().strip() if not insumo or not estado or not ubicacion or not fecha: messagebox.showerror("Error", "Todos los campos deben estar llenos.") return nuevo_movimiento = { "Insumo": insumo, "Estado": estado, "Ubicación": ubicacion, "Fecha": fecha } try: collection.insert_one(nuevo_movimiento) messagebox.showinfo("Éxito", "Movimiento registrado exitosamente") limpiar_campos() cargar_datos() except Exception as e: messagebox.showerror("Error de Base de Datos", f"Error al insertar datos: {e}") # Función para cargar datos desde MongoDB en la tabla def cargar_datos(): for item in tree.get_children(): tree.delete(item) documentos = collection.find() for documento in documentos: insumo = documento.get("Insumo", "N/A") estado = documento.get("Estado", "N/A") ubicacion = documento.get("Ubicación", "N/A") fecha = documento.get("Fecha", "N/A") tree.insert("", "end", values=(insumo, estado, ubicacion, fecha)) # Función para limpiar campos de entrada def limpiar_campos(): insumo_entry.delete(0, tk.END) estado_combobox.set('') ubicacion_combobox.set('') fecha_entry.delete(0, tk.END) # Configuración de la ventana principal root = ctk.CTk() root.title("Reporte de Movimientos de Materia Prima") root.geometry("850x500") # Conectar a la base de datos collection = conectar_db() # Crear un marco para los campos de entrada entrada_frame = ctk.CTkFrame(root) entrada_frame.pack(pady=10, padx=20, fill="x") # Crear los campos de entrada dentro del marco insumo_label = ctk.CTkLabel(entrada_frame, text="Insumo:") insumo_label.pack(pady=(20, 5), anchor="w") insumo_entry = ctk.CTkEntry(entrada_frame, placeholder_text="Ingrese el insumo (e.g., tabla, polín)") insumo_entry.pack(pady=5, fill="x") estado_label = ctk.CTkLabel(entrada_frame, text="Estado:") estado_label.pack(pady=5, anchor="w") estado_combobox = ctk.CTkComboBox(entrada_frame, values=["En Movimiento", "En Existencia"]) estado_combobox.pack(pady=5, fill="x") ubicacion_label = ctk.CTkLabel(entrada_frame, text="Ubicación:") ubicacion_label.pack(pady=5, anchor="w") ubicacion_combobox = ctk.CTkComboBox(entrada_frame, values=["TEJABAN", "ALMACÉN", "PARTE DE ATRÁS"]) ubicacion_combobox.pack(pady=5, fill="x") fecha_label = ctk.CTkLabel(entrada_frame, text="Fecha:") fecha_label.pack(pady=5, anchor="w") fecha_entry = ctk.CTkEntry(entrada_frame, placeholder_text="Ingrese la fecha (dd/mm/yyyy)") fecha_entry.pack(pady=5, fill="x") # Botón para registrar el movimiento registrar_btn = ctk.CTkButton(root, text="Registrar Movimiento", command=registrar_movimiento) registrar_btn.pack(pady=10) # Tabla para mostrar los datos tree = ttk.Treeview(root, columns=("Insumo", "Estado", "Ubicación", "Fecha"), show="headings", height=10) tree.heading("Insumo", text="Insumo") tree.heading("Estado", text="Estado") tree.heading("Ubicación", text="Ubicación") tree.heading("Fecha", text="Fecha") tree.pack(pady=10, padx=20, fill="both", expand=True) # Cargar datos iniciales cargar_datos() root.mainloop()

Prompt
Component Preview

About

UserRegistration - Effortlessly register users with input fields, validation, and MongoDB integration. Built with React and Tailwind. Get instant access!

Share

Last updated 1 month ago