Skip to content
Advertisement

Why is my Tkinter button not executing my function?

JavaScript

I want the function to display heads or tails(randomly). Instead, the function displays nothing and ignores the function. I have also tried printing the value instead of displaying it on tkinter, but it only shows heads and not tails. If any additional details are needed to solve my issue please comment and I will provide additional details.

Advertisement

Answer

In the function open_coin, when the button coin is clicked, you are creating the label but not specifying the x and y coordinates in place , and that too creating everytime the button is pressed. So, create a label to display the result and keep changing its text using config.

And the random function is called only once, so keep it inside the flip function to call everytime in order to get a new random coin value.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement