I'm making a DB "manager" to practice a bit and ran into an absurd problem, which I have no idea why.
It turns out that in a section the name of the database is selected through an Entry, the problem is that when wanting to obtain this name and pass it as a variable, it simply does not grab anything. I try doing prin() in the terminal and it just prints a blank.
botonvalor= IntVar()
def connect():
root3=Tk()
root3.title("Conectar...")
Label(root3, text="Introduce el nombre de la base").grid(row=0, column=0)
nombre= StringVar()
box=Entry(root3,textvariable=nombre)
box.grid(row=1, column=0)
boton2=Button(root3, text="Aceptar",command= botonvalor.set(1))
boton2.grid(row=2, column=0)
root3.wait_variable(botonvalor)
nombre2=nombre.get()
print(nombre2)
root3.mainloop()
With the code like this, it doesn't directly print anything, it remains inert so to speak.
But taking out the button command and everything related to the buttonvalue variable, it prints blank...
The method you are using doesn't make much sense to me. Also as a recommendation, when you are working with an Input type (Text, Entry...) create a super class to be able to use the proxy method and obtain the changes in its value.
Solution
For this case, the most logical solution I could think of was the following.
Declaring widgets
You can save a lot of code when declaring the button and the Entry Widget by using the following.
Getting the input
We create a function to establish the connection. From argument, the text widget. In this way, connecting the button command with the function through a lambda we can obtain the value of the text.
Implement when button is declared
Modifying the button already created