AttributeError: ‘NoneType’ object has no attribute ‘cget’

Issue

This Content is from Stack Overflow. Question asked by ReDRaiN

Im starting to learn python and tkinter code,
im gettint some troubles doing this simple windows whith a button, and when the button was pressed it should disable itself.

#the complete error————————-

*File “C:Usersa441868Desktopproyecto aplicacion it suportvenvprueba botones.py”, line 4, in toggle_state
if button1.cget(“state”) == “normal”:
AttributeError: ‘NoneType’ object has no attribute ‘cget’
Exception in Tkinter callback
Traceback (most recent call last):
File “C:pythonlibtkinter_init_.py”, line 1921, in call
return self.func(args)

#code——————–


   def toggle_state():
       if button1.cget("state") == "normal":
           button1.config(state="disabled")
           label1.config(text='COMPLETADO',bg='green')
           return
       else:
           button1.config(state="normal")
           label1.config(text='PENDIENTE')

root = Tk()
root.geometry('400x400')

button1 = Button(root, text="Exportar marcadores Chrome",command=toggle_state).grid(column=0,row=0)
root.mainloop()



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?