0
votes

First of all this is my code:

button_1 = Button(
        image=button_image_1,
        borderwidth=0,
        highlightthickness=0,
        command=lambda:[get_to_main_when_clicked(),delete_red_border()],
        relief="flat"
    )

As you can see I binded 2 functions to this button. To the first one: If a specific condition is true, then the function lets an image appear. The second one then should wait 3 seconds and should delete the appeared image. The only really weird problem is, that it no matter what I do, first executes the delete_red_border() function. It waits 3 seconds, then its trying to delete an image that couldn't be defined and globalized, because the get_to_main_when_clicked() function wasn't executed. How can I solve this? PS: The specific condition is true.

2
Maybe instead of adding both functions in the command, just add the get_to_main_when_clicked() function, and at the end of get_to_main_when_clicked() you can use after(3000, delete_red_border)BrianZhang
Your lambda creates a list, the first item is evaluated first. I guess the problem is somewhere else ...Maurice Meyer
Yea I think I found the problem, I described it in a comment under the other answer, but yesss, BrianZhang you're totaly right, pretty obvious and a way easier solution. Thanks a lot!the_guy71639
damn doesnt work either, I guess it's because the same problemthe_guy71639
the window doesnt get refreshed till the function is done runningthe_guy71639

2 Answers

0
votes

Don't do this. Create a function specifically for this button. A function is much easier to understand and debug than a lambda, especially a complex lambda. You can then put any logic you want inside the function.

def do_something():
    get_to_main_when_clicked()
    delete_red_border()

button_1 = Button(..., command=do_something)
0
votes

I found the solution for it. The problem was, that it didn't refreshed/updated the window after finishing the first function. That was solved by one line of code:

window.update()