Skip to content

Quick Start Guide 3: TODO Task App not working, one too many indentation #108

@PeterAdam

Description

@PeterAdam

Running this example leads to:

P:\python>python todo.py Traceback (most recent call last): File "P:\python\todo.py", line 40, in <module> main() ~~~~^^ File "P:\python\todo.py", line 34, in main app = TodoApp(Application) File "P:\python\todo.py", line 20, in __init__ self.add_task_btn.OnClick = self.__add_task_on_click ^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: Error in getting property "_TodoApp__add_task_on_click". Error: Unknown attribute

because the class instance methods indented one too much, they became part of init:

class TodoApp(Form):
    def __init__(self, Owner):
        self.Caption = "A TODO GUI Application"
        self.SetBounds(100, 100, 700, 500)
        
        Removed for clarity

        self.list_of_tasks.SetBounds(300, 50, 300, 350)

        def __add_task_on_click(self, Sender):
            self.list_of_tasks.Items.Add(self.task_text_box.Text)
            self.task_text_box.Text = ""

        def __del_task_on_click(self, Sender):
            self.list_of_tasks.Items.Delete(0)

Decreasing the indentation fixes the example:

        self.list_of_tasks.SetBounds(300, 50, 300, 350)
        
    def __add_task_on_click(self, Sender):
        self.list_of_tasks.Items.Add(self.task_text_box.Text)
        self.task_text_box.Text = ""

    def __del_task_on_click(self, Sender):
        self.list_of_tasks.Items.Delete(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions