File: class/Workbook/Examples/Lecture11/buttonpics1.py

from Tkinter import *                # get base widget set
from glob import glob                # file name expansion
import hellouseCheck                 # attach the last example to "me"
import random                        # pick a picture at random
gifdir = '../../../Part3/Gui/gifs/'  # where to look for gif files

def draw():
    name, photo = random.choice(images)
    lbl.config(text=name)
    pix.config(image=photo)

root=Tk()
lbl = Label(root,  text="none", bg='blue', fg='red')
pix = Button(root, text="Press me", command=draw, bg='white')
lbl.pack(fill=BOTH)
pix.pack(pady=10)
hellouseCheck.HelloContainer(root, relief=SUNKEN, bd=2).pack(fill=BOTH)

files = glob(gifdir + "*.gif")
images = map(lambda x: (x, PhotoImage(file=x)), files)
print files
root.mainloop()



[Home page] Books Code Blog Python Author Train Find ©M.Lutz