#πŸ”’ Needing help to understand the coincidents beetween self and attributes

24 messages Β· Page 1 of 1 (latest)

scarlet mesaBOT
#

@inland sail

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

inland sail
#

So what I’m trying is to just do 1 command, which then works based on which button was clicked. To indicate that, I’m trying to give 2 values into the function

#

But that leads to the posted problem. I guess it’s caused by my relative new python skills

#

So if someone can explain me what I might misunderstood, I would highly appreciate.

#

Needing help to understand the coincidents beetween self and missing attributes

fringe sand
#

In a nutshell:

self.scoreboard_frame_button_1 = customtkinter.CTkButton(self.scoreboard_frame, text="+", height=20, width=20, command=self.on_scoreboard_change(1, 1))
...
self.team1_score_label = customtkinter.CTkLabel(self.scoreboard_frame, text="0", font=customtkinter.CTkFont(size=25))

Because on_scoreboard_change is being called in the first line above, and that method attempts to reference self.team1_score_label, at the time the CTkButton is being created there is no attribute team1_score_label (because it has not been assigned yet).

#

Try moving the assignment of self.team1_score_label above the assignment for self.score_board_frame_button1 inside __init__.

#

Generally, we should try to avoid too many other method calls inside __init__ for this reason. The order of operations is important, and if something is trying to reference something that hasn't been assigned yet, you get these errors.

#

In this case, though, just re-ordering things in __init__ should be fine

inland sail
fringe sand
#

Don't be too hard on yourself. These are good lessons to find out about. πŸ™‚

inland sail
# fringe sand Try moving the assignment of `self.team1_score_label` above the assignment for `...

~~Ok this got me a step forward. However i now get this.
File "c:\Users\lucao\Documents\GitHub\WTeS-Scoreboard-Tool\ScoreTest.py", line 73, in init
self.scoreboard_frame_button_1 = customtkinter.CTkButton(self.scoreboard_frame, text="+", height=20, width=20, command=self.on_scoreboard_change(1, 1))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\lucao\Documents\GitHub\WTeS-Scoreboard-Tool\ScoreTest.py", line 117, in on_scoreboard_change
self.team2_score_label.configure(text=self.scoreboard[2])
~~~~~~~~~~~~~^^^
IndexError: list index out of range
fixed it by adding self.scoreboard= [0, 0, 0] to the definitions of the variables

#

is it that list start reading from 0 on?

#

But still nothing changes when clicking my plus an minus buttons

inland sail
fringe sand
#

Don't know enough about tkinter unfortunately, I don't think I can be of much more help.

inland sail
#

So actual problem, basically nothing changes when clicking + or -

#

No error or anything. Just no change when clicking

scarlet mesaBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.