AttributeError: 'NoneType' object has no attribute 'cget'

Viewed 24

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:\Users\a441868\Desktop\proyecto aplicacion it suport\venv\prueba 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:\python\lib\tkinter_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()
1 Answers

NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None. That usually means that an assignment or function call up above failed or returned an unexpected result.

Related