DelphiFMX4Python icon indicating copy to clipboard operation
DelphiFMX4Python copied to clipboard

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

Open PeterAdam opened this issue 3 months ago • 0 comments

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)

PeterAdam avatar Sep 04 '25 22:09 PeterAdam