I need that when reaching seven characters, the two widgets below change their state to active. The code runs fine, but when I type the seven characters below, they don't fire. Who can correct me, thanks.
marco_ticket = customtkinter.CTk()
marco_ticket.geometry(f"{600}x{300}")
marco_ticket.title("Control de Pesajes Baelca")
#Función validar placa
def validar_placa():
texto=entry_placa.get()
if len(texto) >=7:
entrada.configure(State="normal")
entrada2.configure(state="normal")
else:
pass
label_placa=customtkinter.CTkLabel(marco_ticket, text="Placa :", text_font=("arial", 16))
label_placa.grid(column=0, row=0, pady=5, padx=5)
entry_placa=customtkinter.CTkEntry(marco_ticket)
entry_placa.grid(column=1, row=0, pady=5, padx=50)
entrada=customtkinter.CTkComboBox(marco_ticket, values=["Lleno", "Vacio", "Pesada múltiple"], state="disabled")
entrada.grid(column=0, row=1, pady=5, padx=5)
entrada.set("Lleno")
entrada2=customtkinter.CTkEntry(marco_ticket, state="disabled")
entrada2.grid(column=0, row=2, pady=5, padx=5)
validar_placa()
marco_ticket.mainloop()
The problem is that your function is executed only once (below input2). You don't associate it with any validators, control variables, or anything that might tell Tkinter that the function should be executed or when.
One way to get the function to run whenever the user types or pastes something would be to use a validator. A validator is a feature of Tkinter (not just customtkinter) in which you can bind functions to certain events (like write events) with a tuple like this
funcion
must always return True or False (an empty list doesn't count). Otherwise, the validator will be disabled.In this case, we are going to use
validate="key"
to say that it should be activated when the user types, we are going to tell it to pass the argument"%P"
(which is the text that the entry would have if the validation passed) and we will make the function always return True, since , for now, we are not actually validating the entry and therefore every action should be considered valid.Here is the code with an additional fix:
I spoke in a very brief way about the validators, since in reality, I want some information to be preserved in case the tutorial whose link I intend to put ceases to exist.
This is the link of the tutorial: https://recursospython.com/guias-y-manuales/validar-el-contenido-de-una-caja-de-texto-en-tkinter/