I am working on a program to close the basic programming course of the university. The purpose of the program is to make the return of lost electronic objects within the U easier and safer. I am working in python and I am new to the graphic interface tkinter.
It turns out that to create several windows in tkinter, use different functions which you called through a button. The function def registrar_dispositivo_funcion()
has the objective of entering different information related to the student, a window that will open when you press the "register device" button. In this function I have a frame where the information is captured in the variable nombre
and apellido
(indicated in an arrow). I want to obtain that information and store it in a database through .get()
. The problem is that I can not capture the information or the text inside the function when I press the "SAVE" button because it shows me absolutely nothing.
What I have tried to know that the variable returns to me, is to directly print the variable with .get
. but in the same way the action shows absolutely nothing.
This is the code, it's a bit long. I hope you can help me.
from tkinter import *
import tkinter as tk
from tkinter import messagebox #libreria mensajes de error
import pymongo
dispmov=[]
###########################################################################
#funcion validar
def validar_funcion():
if entrada1.get()== "12345":#.get permite recoger la info del cuadro de txt
menu_funcion()
else:
messagebox.showwarning("Cuidado", "password incorrecto")#despliega msj
#######################################################
#FUNCION ALMANCENAR EN DICCIONARIO
def almacenar_funcion(nombre):
print("Nombre:",nombre.get())
#######################################################
#FUNCION CERRRAR VENTANA
def cerrarventana():
ventana.destroy()
menu_frame.destroy()
###############################################################
def menu_funcion():
ventana.withdraw()
menu_frame = tk.Toplevel()
#titulo de la ventana
menu_frame.title("U FIND")
#tamaño de la ventana
menu_frame.geometry("1000x680+0+0")
#TEXTO "BIENVENIDOS A UVG FIND"FIJO
OPCION1=Frame(menu_frame, width="330", height="65")
OPCION1.grid(row=1, column=1, padx=0, pady=0)
OPCION1.config(bg="black")
OPCION1.config(relief="groove")
OPCION1.config(bd=15)
Label(OPCION1, text="BIENVENIDOS A U FIND", fg="gray", font=("Bauhaus
93",20)).place(x=0,y=0)
#---------------------------------------------------------
#BOTONES
boton_registro_menu=Button(menu_frame, text="REGISTRAR UN DISPOSITIVO",
font=("Bauhaus 93",15),
background="gray",borderwidth=20,command=registrar_dispositivo_funcion)
.place(x=100,y=300)
boton_verificar_menu=Button(menu_frame, text=" VERIFICAR
PROPIETARIO DEL \n DISPOSITIVO", font=("Bauhaus 93",13),
background="gray",borderwidth=20).place(x=100,y=400)
boton_remplazar_menu=Button(menu_frame, text=" REMPLAZAR DISPOSITIVO ",
font=("Bauhaus 93",15),
background="gray",borderwidth=20).place(x=100,y=500)
boton_agregar_menu=Button(menu_frame, text=" AGREGAR UN DISPOSITIVO
", font=("Bauhaus 93",15),
background="gray",borderwidth=20).place(x=600,y=300)
var=Button(menu_frame, text="¿COMO SE DONDE ESTA EL NUMERO \n DE SERIE DE
MI DISPOSITIVO?", font=("Bauhaus 93",13),
background="gray",borderwidth=20).place(x=600,y=400)
opciones=['laptop','telefono','tablet']
boton_buscar_menu=OptionMenu(menu_frame,var, *opciones)
boton_salir_menu=Button(menu_frame, text=" SALIR
", font=("Bauhaus 93",15), background="gray",borderwidth=20,
command=menu_frame.destroy).place(x=600,y=500)
#######################################################################
# FUNCION REGISTRAR UN DISPOSITIVO MOVIL
def registrar_dispositivo_funcion():
#menu_frame.withdraw()
ventana.withdraw()
raiz = tk.Tk()
#titulo de la ventana
raiz.title("U FIND")
#tamaño de la ventana
raiz.geometry("1000x680+0+0")
#TEXTO "VENTANA DE INGRESO DE DATOS"FIJO
OPCION1=Frame(raiz, width="417", height="65")
OPCION1.grid(row=1, column=1, padx=0, pady=0)
OPCION1.config(bg="black")
OPCION1.config(relief="groove")
OPCION1.config(bd=15)
Label(OPCION1, text="VENTANA DE INGRESO DE DATOS", fg="gray",
font=("Bauhaus 93",20)).place(x=0,y=0)
#---------------------------------------------------------
#INGRESO DE DATOS PERSONALES
#frame
DATOS=Frame(raiz, width="198", height="165")
DATOS.grid(row=2, column=1, padx=10, pady=40)
#solicitud nombre
nombre = tk.StringVar(DATOS)
tk.Entry(DATOS, textvariable=nombre, width=30).place(x=70,y=40)
tk.Label(DATOS, text =
'Nombre:').place(x=0,y=40)#fila,columna,orientacion,margene,margen
#solicitud apellido
apellido=tk.StringVar(DATOS)
txtApellido=tk.Entry(DATOS, textvariable=apellido).place(x=70, y=80)
tituloApellido=Label(DATOS, text="Apellido:", padx=10,
pady=10).place(x=0,y=80)
# |\
#====================== \
#====================== /
# |/
#BOTONO GUARDAR
Boton_guardar=tk.Button(DATOS,text="GUARDAR", fg="blue",font=("Agency
FB",14),command=almacenar_funcion(nombre))
Boton_guardar.place(x=80,y=100)
print("Nombre2:",nombre.get())
print("apellido:",apellido.get())
#color
raiz.config(bg="green")
################################################################
# VENTANA CONTRASEÑA
ventana=tk.Tk()#origen del programa
ventana.title("ventana1")
ventana.geometry("1075x600+0+0")
ventana.configure(background="green")
#titulo de la ventana
ventana.title("U FIND")
#LOGO U
#se crea el frame
LOGO=Frame(ventana, width="310", height="290")
#empaquetar el frare
LOGO.grid(row=0, column=1, padx=380, pady=50)
LOGO.config(bg="white")#color
#miFrame.config(width="650", height="350")
#formato cuadro
LOGO.config(relief="groove")
LOGO.config(bd=15)
LOGO.config(cursor="pirate")
#IMAGEN
#TEXTO "VENTANA DE INGRESO DE DATOS" FIJO
OPCION1=Frame(ventana, width="330", height="65")
OPCION1.grid(row=1, column=1, padx=0, pady=0)
OPCION1.config(bg="black")
OPCION1.config(relief="groove")
OPCION1.config(bd=15)
Label(OPCION1, text="INGRESE LA CONTRASEÑA", fg="gray", font=("Bauhaus
93",20)).place(x=0,y=0)
#etiqueta para el ingreso del password
e1=tk.Label(ventana,text="password", bg="pink", fg="white").place(x=410,
y=475)
entrada1=tk.Entry(ventana)
entrada1.grid(row=3, column=1,padx=0, pady=20)
entrada1.config(show="*", fg="red", justify="center")
#BOTON NUEVA VENTANA
boton=tk.Button(ventana,text="nueva ventana", fg="blue",
command=menu_funcion).grid(row=4, column=1,padx=0, pady=5)
#BOTON VALIDAR
boton3=tk.Button(ventana,text="validar pasword", fg="blue",
command=validar_funcion).grid(row=5, column=1,padx=0, pady=5)
################################################################
#ciclo de la interfaz
ventana.mainloop()