The problem is, you are using the same attributes to assign widget and widget instances StringVars on the load tab form and in the query box.. This makes what returns you from the load tab is the content of the query tab entries, which are empty.It would suffice to rename the class attributes you define in consulta_por_dni so that new objects are not reassigned to those defined in carga_sociosfor example by passing self.dnicarga a self.dniconsulta And so with the rest.However, consider using some additional classes to define the forms in each tab, thus separating the code and you can reuse it. Apparently both the load tab and the query tab has the same form, it doesn't make sense that you type the same code twice when you can use a class and instance the times you want. There might be something like that.import tkinter as tk
from tkinter import ttk
from tkinter import messagebox as mb
from tkinter import scrolledtext as st
import socios
class SocioForm(ttk.Frame):
def init(self, master, *args, **kwargs):
super().init(master, *args, **kwargs)
self.labelframe = ttk.LabelFrame(self, text='Socios')
self.labelframe.grid(column=0, row=0, padx=5, pady=10)
self.label_dni = ttk.Label(self.labelframe, text='Dni:')
self.label_dni.grid(column=0, row=0, padx=4, pady=4)
self.dni = tk.StringVar()
self.entry_dni = ttk.Entry(self.labelframe, textvariable=self.dni)
self.entry_dni.grid(column=1, row=0, padx=4, pady=4)
self.label_nombre = ttk.Label(self.labelframe, text='Nombre:')
self.label_nombre.grid(column=0, row=1, padx=4, pady=4)
self.nombre = tk.StringVar()
self.entry_nombre = ttk.Entry(self.labelframe, textvariable=self.nombre)
self.entry_nombre.grid(column=1, row=1, padx=4, pady=4)
self.label_apellido = ttk.Label(self.labelframe, text='Apellido:')
self.label_apellido.grid(column=0, row=2, padx=4, pady=4)
self.apellido = tk.StringVar()
self.entry_apellido = ttk.Entry(self.labelframe, textvariable=self.apellido)
self.entry_apellido.grid(column=1, row=2, padx=4, pady=4)
self.label_sexo = ttk.Label(self.labelframe, text='Sexo:')
self.label_sexo.grid(column=0, row=3, padx=4, pady=4)
self.sexo = tk.StringVar()
self.entry_sexo = ttk.Entry(self.labelframe, textvariable=self.sexo)
self.entry_sexo.grid(column=1, row=3, padx=4, pady=4)
self.label_fecha = ttk.Label(self.labelframe, text='Fecha de Nacimiento:')
self.label_fecha.grid(column=0, row=4, padx=4, pady=4)
self.fecha = tk.StringVar()
self.entry_fecha = ttk.Entry(self.labelframe, textvariable=self.fecha)
self.entry_fecha.grid(column=1, row=4, padx=4, pady=4)
self.label_direccion = ttk.Label(self.labelframe, text = 'Dirección:')
self.label_direccion.grid(column=0, row=5, padx=4, pady=4)
self.direccion = tk.StringVar()
self.entry_direccion = ttk.Entry(self.labelframe, textvariable=self.direccion)
self.entry_direccion.grid(column=1, row=5, padx=4, pady=4)
self.label_plan = ttk.Label(self.labelframe, text='Plan:')
self.label_plan.grid(column=0, row=6, padx=4, pady=4)
self.plan = tk.StringVar()
self.entry_plan = ttk.Entry(self.labelframe, textvariable=self.plan)
self.entry_plan.grid(column=1, row=6, padx=4, pady=4)
self.label_telefono = ttk.Label(self.labelframe, text='Telefono:')
self.label_telefono.grid(column=0, row=7, padx=4, pady=4)
self.telefono = tk.StringVar()
self.entry_telefono = ttk.Entry(self.labelframe, textvariable=self.telefono)
self.entry_telefono.grid(column=1, row=7, padx=4, pady=4)
self.boton_aceptar = ttk.Button(self.labelframe, text="Aceptar")
self.boton_aceptar.grid(column=1, row=8, padx=4, pady=4)
def get_data(self):
datos = (self.dni.get(), self.nombre.get(),
self.apellido.get(), self.sexo.get(),
self.fecha.get(), self.direccion.get(),
self.plan.get(), self.telefono.get()
)
return datos
class Listado(ttk.Frame):
def init(self, master, *args, **kwargs):
super().init(master, *args, **kwargs)
self.master = master
self.labelframe = ttk.LabelFrame(self, text='Socios')
self.labelframe.grid(column=0, row=0, padx=5, pady=10)
self.boton = ttk.Button(self.labelframe,
text='Listado completo')
self.boton.grid(column=0, row=0, padx=4, pady=4)
self.scrolledtext = st.ScrolledText(self.labelframe, width=30, height=10)
self.scrolledtext.grid(column=0, row=1, padx=10, pady=10)
class FormularioSocios(ttk.Notebook):
def init(self, master, *args, **kwargs):
super().init(master, *args, **kwargs)
self.socio = Socios()
self.carga_form = SocioForm(self)
self.add(self.carga_form, text='Carga de Socios')
self.carga_form.boton_aceptar.config(command=self.agregar,
text="Cargar")
self.consulta_form = SocioForm(self)
self.add(self.consulta_form, text='Consulta por Dni')
self.consulta_form.boton_aceptar.config(command=self.consultar,
text="Consultar")
self.listado = Listado(self)
self.add(self.listado, text='Listado Completo')
self.listado.boton.config(command=self.listar)
def agregar(self):
datos = self.carga_form.get_data()
self.socio.alta(datos)
mb.showinfo('Información', 'Los datos fueron cargados')
print(datos)
def consultar(self):
datos = self.consulta_form.get_data()
respuesta = self.socio.consulta(datos)
if len(respuesta) > 0:
self.consulta_form.dni.set(respuesta[0][0])
self.consulta_form.set.set(respuesta[0][1])
else:
self.consulta_form.dni.set('')
self.consulta_form.nombre.set('')
mb.showinfo("Información", "No existe un artículo con dicho código")
def listar(self):
respuesta = self.socio.recuperar_todos()
self.listado.scrolledtext.delete("1.0", tk.END)
for fila in respuesta:
text = f"código: {fila[0]}\ndni: {fila[1]}\nnombre: {fila[2]}\n\n"
self.listado.scrolledtext.insert(tk.END, text)
if name == "main":
root = tk.Tk()
form = FormularioSocios(root)
form.grid(column=0, row =0, padx =10, pady = 10)
root.mainloop()