2

I'm currently making a coin flipping simulator with GUI. When I run the code, the program shows a random object of my list in a tkinter.Label(), and as I press the button, nothing happens. I want that at first no text is visible and if I press the button, it will choose a random object of the list. So here's my code:

#import mudules
import random, sys, tkinter
random.seed()
main = tkinter.Tk()
main.title("Coin flipping simulator")
main.geometry("300x200")

#list
options = ["Head", "Number"]

def flip():
    coin = random.choice(options)
    text = tkinter.Label(text = coin)
    text.pack()

buttonFlip = tkinter.Button(main, command=flip(), text="Flip coin!")

buttonFlip.pack()
buttonFlip.place(x=150, y=100, anchor="center")

#end
main.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Clood
  • 31
  • 2

1 Answers1

3
buttonFlip = tkinter.Button(main, command=flip(), text="Flip coin!")

This executes the flip function try:

buttonFlip = tkinter.Button(main, command=flip, text="Flip coin!")
vkluge
  • 324
  • 3
  • 11