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()