Images Local
local images.py
#1. initialise:
from tkinter import *
from random import *
window = Tk()
#2. variables and widgets:
#PhotoImage is .gif only, no .jpg or .png
#Keep images in same location as .py:
imgHeads = PhotoImage(file="heads.gif")
imgTails = PhotoImage(file="tails.gif")
btnFlip = Button(text="Flip")
lblPicture = Label(image=imgHeads)
#3. events:
def flipCoin(event):
if(randint(1,2)==1):
lblPicture.configure(image=imgHeads)
else:
lblPicture.configure(image=imgTails)
#4. bindings:
btnFlip.bind("<ButtonPress>", flipCoin)
#5. pack:
lblPicture.pack()
btnFlip.pack(fill=BOTH) #stretches button
#6. run:
window.mainloop()
You will need to save heads.gif and tails.gif to the same folder as your python file is in for this script to work.heads.gif
tails.gif