-1

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()
ReDRaiN
  • 1
  • 1
  • Does this help? if button1['state'] == NORMAL: – toyota Supra Sep 19 '22 at 16:43
  • def toggle_state() -> None: if button1['state'] == NORMAL: button1['state'] = DISABLED label1.config(text='COMPLETADO',bg='green') return else: button1['state'] = NORMAL button1.config(state="normal") label1.config(text='PENDIENTE') – toyota Supra Sep 19 '22 at 16:50

1 Answers1

0

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.

Usama Arslan
  • 111
  • 4