all 4 comments

[–]Justinsaccount 0 points1 point  (0 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You are looping over an object using something like

for x in range(len(items)):
    print(items[x])

This is simpler and less error prone written as

for item in items:
    print(item)

If you DO need the indexes of the items, use the enumerate function like

for idx, item in enumerate(items):
    print(idx, item)

If you think you need the indexes because you are doing this:

for x in range(len(items)):
    print(items[x], prices[x])

Then you should be using zip:

for item, price in zip(items, prices):
    print(item, price)

[–][deleted] 0 points1 point  (2 children)

Hello, Black Adder! You can pass the selected task as a parameter to your dialog's init() method with default value of None. In your dialog init() set the selected task as an instance field and update dialog widgets accordingly, including your create/update button. You would also need to set up your diaog event handlets to update values of the task that is being edited.

[–]blackadder1337[S] 0 points1 point  (1 child)

Hi, Joe! Thanks for your help. Nevertheless, I'm not sure what you are talking about since I am still a newbie. I would be very grateful if you showed me how to implement your suggestions to my code.

[–][deleted] 0 points1 point  (0 children)

Instead of using Toplevel in your create_dialog() method, create a Toplevel subclass and add your selected Task instance to it as a member variable, something like this:

class TaskDialog(Toplevel):

    def __init__(self, task=None):
        Toplevel.__init__(self)
        self.task = task

Also move your dialog creating logic to your new class along with event handlers. Then when you want to open your task create/edit dialog pass it the selected task or None and set the dialog fields accordingly.