I wanted to implement a window, using Python and Tkinter, which allows the user to enter different data and it is displayed right below it. Likewise, I wanted to modify the logo that comes by default in the window. To do this, in the same folder where I have the module, I included the logo, with the extension, .ico
but I get the error _tkinter.TclError: couldn't open "Logo": no such file or directory" not defined
. I also tried without mentioning the extension, but I get the same error
In the same way, I wanted to know if there is any tool that, from the documented code, generates its own documentation of use.
I attach the code and the "prototype" of what I want to develop
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
def ventanaCapturaDatos():
def devolverDatos():
textoCaja=entryTexto.get()
texto.set(textoCaja)
root.destroy()
root=Tk()
root.title("Entrada de datos")
#FRAME DE ENTRADA DE DATOS
miFrame=Frame(root)
miFrame.pack()
texto=StringVar()
#ENTRY
entryTexto = Entry(miFrame, justify=CENTER ,textvariable=texto)
entryTexto.grid(row=0, column=0, padx=5, pady=5)
root.iconbitmap('Logo.ico') # No consigo que el logo se muestre
root.geometry('350x200')
#BOTÓN ACEPTAR
botonAceptar=Button(miFrame, text="Aceptar", command=lambda:devolverDatos())
botonAceptar.grid(row=1, column=0, sticky="e", padx=5, pady=5)
root.mainloop()
return texto.get()
print("Llamamos a la ventana de entrada de datos")
texto=ventanaCapturaDatos()
print("El texto que has introducido es:")
print(texto)
As for modifying the program icon, I had the same problem in Kubuntu 18.04 and I never knew the reason, but I solved it by redefining the function
root.iconbitmap
like this:Now if you run it
root.iconbitmap('icon.ico')
should work.To display the data entered by the user you can use a
Listbox
. If the amount of data is arbitrary, the list should ideally be scrollable . Inside the functionventanaCapturaDatos
you can create aFrame
that contains an objectListbox
associated with an objectScrollbar
:Now you just have to modify the function
devolverDatos
so that it adds the text of the entry to the listbox :As for the documented code, I honestly have no idea, not documenting the code is one of my bad habits hehe. All the best.