Python Tkinter error object has no attribute
Your initial call to guess_number
in your initializer method is probably being invoked before you press the button and trigger the new_window
event callback. In guess_number
you're trying to pass self.window
as an argument to Label()
but it would be undefined at that time.
First at all, you should never create a new attribute out of the __init__
method.
That said, Mike pointed the trouble’s reason: you created the window object inside the new_window
method, but did not called it.
You must call new_window
before call guess_number
– or call one inside other.
I suggest that you set window
to None
and call new_window
inside __init__
method, then (after that) call guess_number
.