Example 8-39. PP4E\Gui\Tour\imgCanvas2.py
gifdir = "../gifs/"
from sys import argv
from tkinter import *
filename = argv[1] if len(argv) > 1 else 'ora-lp4e.gif' # name on cmdline?
win = Tk()
img = PhotoImage(file=gifdir + filename)
can = Canvas(win)
can.pack(fill=BOTH)
can.config(width=img.width(), height=img.height()) # size to img size
can.create_image(2, 2, image=img, anchor=NW)
win.mainloop()
Figure 8-38. An image on canvas
Figure 8-39. Sizing the canvas to match the photo
486 | Chapter 8: A tkinter Tour, Part 1