namephoto random choice(imageslbl config(text=namepix config(image=photoroot=tk(lbl label(roottext="none"bg='blue'fg='red'pix button(roottext="press me"command=drawbg='white'lbl pack(fill=bothpix pack(pady= democheck demo(rootrelief=sunkenbd= pack(fill=bothfiles glob(gifdir "gif"images [(xphotoimage(file= )for in filesprint(filesroot mainloop(gifs for now load and hold this code uses handful of built-in tools from the python librarythe python glob module we first met in gives list of all files ending in gif in directoryin other wordsall gif files stored there the python random module is used to select random gif from files in the directoryrandom choice picks and returns an item from list at random to change the image displayed (and the gif file' name in label at the top of the window)the script simply calls the widget config method with new option settingschanging on the fly like this changes the widget' display dynamically just for funthis script also attaches an instance of the democheck check button demo bar from example - which in turn attaches an instance of the quitter button we wrote earlier in example - this is an artificial exampleof coursebut it again demonstrates the power of component class attachment at work notice how this script builds and holds on to all images in its images list the list comprehension here applies photoimage constructor call to every gif file in the photo directoryproducing list of (filenameimageobjecttuples that is saved in global variable ( map call using one-argument lambda function could do the samerememberthis guarantees that image objects won' be garbage collected as long as the program is running figure - shows this script in action on windows although it may not be obvious in this grayscale bookthe name of the gif file being displayed is shown in red text in the blue label at the top of this window this program' window grows and shrinks automatically when larger and smaller gif files are displayedfigure - shows it randomly picking taller photo globbed from the image directory tkinter tourpart