CSC111 Programs for Week 10 2015

From dftwiki3
Revision as of 04:48, 6 April 2015 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- <br /> =Skeleton Program for Processing Images= <br /> The program below will work with this image, named "catGlasses.gif". It should be located in the same direc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 05:48, 6 April 2015 (EDT)



Skeleton Program for Processing Images


The program below will work with this image, named "catGlasses.gif". It should be located in the same directory where the program is saved.

CatGlasses.gif


# imageProcessingSkel.py
# D. Thiebaut
# A skeleton program to start doing image processing
# in Python

from graphics import *

# image geometry
# 424x18
# make the window the same geometry
WIDTH  = 424
HEIGHT = 418
IMAGEFILENAME = "catGlasses.gif"

#----------------------------------------------------------------
def waitForClick( win, message ):
    """ waitForClick: stops the GUI and displays a message.  
    Returns when the user clicks the window. The message is erased."""

    # wait for user to click mouse to start
    startMsg = Text( Point( win.getWidth()/2, win.getHeight()-15 ), message )
    startMsg.draw( win )    # display message
    win.getMouse()          # wait
    startMsg.undraw()       # erase

def main():
    # open the window
    win = GraphWin( "Image Editor", WIDTH, HEIGHT )

    # open the cat image
    cat = Image( Point(WIDTH//2, HEIGHT//2), IMAGEFILENAME )
    cat.draw( win )

    waitForClick( win, "click to close" )

    win.close()

main()