Pages

04 November, 2023

AttributeError: 'NoneType' object has no attribute 'config' while True loop

Nothing I try works. I'm trying to change the config of a button within a function called by the button.
from tkinter import *

root= Tk()
# window config here
btn = Button(root, text="Start", command="toggle").pack()

def toggle():
if btn.config('text')[-1] == 'Start':
btn.config('text')[-1] == 'Stop'
elif btn.config('text')[-1] == 'Stop':
btn.config('text')[-1] == 'Start'

while btn.config('text')[-1] == 'Stop': # Error throws here
print('click')

root.mainloop()



It keeps throwing AttributeError: 'NoneType' object has no attribute 'config' regarding commented line

No comments:

Post a Comment

Thanks