[Python-es] Problemas con tkinter

Javier Perez javierperez en perasalvino.es
Mar Nov 17 06:27:16 EST 2020


Hola a todos,


Estoy empezando a usar tkinter. Tengo dos problemas:
1) no se como sacar la información del formulario. El caso es que tengo una funcion que si lo recoge pero no lo retorna. No llego a entender lo que pasa. 

2) Después, al cerrar la venta, me muestra este error la consola: 
result = textExample.get("1.0", "end")
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 3706, in get
 return self.tk.call(self._w, 'get', index1, index2)
_tkinter.TclError: invalid command name ".!text"



El código es este:
import tkinter as tk

root = tk.Tk()
root.geometry("600x400")

​
def getTextInput():
	result = textExample.get("1.0", "end")
	#print(result) # —> si le queto el comentario si me lo imprime
	 return result
	
textExample = tk.Text(root, height=10)
textExample.pack()
btnRead = tk.Button(root, height=2, width=50, text="Introducir en la bbdd", command=getTextInput)

btnRead.pack()
​
root.mainloop()

noticia = getTextInput()
print(noticia)


Muchísimas gracias a todos,

Saludos,

--
Javier Pérez
http://es.linkedin.com/in/javierperez1
http://www.perasalvino.es/






Más información sobre la lista de distribución Python-es