Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError
#1
I am using code to try to learn python. I am getting an AttributeError which I cannot figure out. Here is the error.

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Python\gui_cell_set_state.py", line 31, in _on_click
self.set_state(not self.active)
AttributeError: 'Cell' object has no attribute 'active'

I have copied the code exactly as it was written in the instructions and it seems to work until I try to Click on a box. That is the code presents the canvas with its boxes properly but when I try to click on a box to change its state, the error is thrown up. I cannot see what is causing this error. Would appreciate any help I could get. Thanks. The code is below.
david

Attached Files

.py   gui_cell_set_state.py (Size: 2.67 KB / Downloads: 109)
Reply
#2
Line 27: You've missed a dot:

self_active = False

Should be:
self._active = False
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#3
Please post code, not links.
Reply
#4
(Jun-15-2023, 11:04 PM)rob101 Wrote: Line 27: You've missed a dot:

self_active = False

Should be:
self._active = False

Wow! is this language unforgiving. I did not see that at all. Thank you for helping me. Of course it is working fine now. Thanks again.
david
rob101 likes this post
Reply
#5
Those irritating programming languages that require you to write the code correctly for it to work.
Reply
#6
(Jun-16-2023, 05:05 PM)foxxrunning Wrote: Wow! is this language unforgiving. I did not see that at all. Thank you for helping me. Of course it is working fine now. Thanks again.
david

You're welcome.
It's an all to easy mistake to make and not that easy to spot, as the error message really only hints at the issue, but as you become more experienced, you'll learn what to look for and where to look.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020