Looping Menu

imagegram.py: 38 points


We’ll start by implementing the menu for your program. Your program should begin by printing a welcome to the user. You should then prompt the user in the console to enter the name of a file to load. You should use a try-except block to make sure that the file exists – if a FileNotFoundError occurs, you should print a message to the user letting them know that the file with the provided name does not exist.

Once you have an image loaded, display it. Next, use a while loop to repeatedly print a list of possible operations and prompt the user to select one of these operations to apply to their image, then apply the selected operation (create a distinct function for each operation), and display the resulting image. Thus, the user might choose to reflect the image, then increase the contrast (of the now reflected image), and then blur (the now reflected and contrasted image). At each step, the user should be able to see the resulting image. For now, since you haven’t actually implemented the functions for the operations yet, you should implement all of the above except actually applying the filters.

picture.run() vs picture.display()

The picture module provides two methods for displaying an image to the screen—picture.run() and picture.display(). Until now, you’ve only been using picture.run(). This function displays the current image and then keeps your program running until the image window is closed. This is useful when you want to display an image once. What if you want to update an image while your program is running? In that case, you’ll need to use picture.display(). This function creates or updates an image window with the current image. However, the image window will close as soon as your program ends. Since your imagegram.py program will use a while loop to monitor the user’s input, you should use picture.display() whenever you want to show the user the current version of their image.

You can find more information about picture.run() and picture.display() in the picture module documentation.

The menu should keep prompting the user to select a filter until they select the Quit option. At the end of this part of the lab, interacting with your program should look something like this:

Welcome to Imagegram!  

Please enter a filename: crayons.jpg

Which of the following filters would you like to apply?

1. Make Negative
2. Make Grayscale
3. Flip Vertically
4. Scroll Horizontally
5. Zoom
6. Blur
0. Quit

Choice: 1

Which of the following filters would you like to apply?
1. Make Negative
2. Make Grayscale
3. Flip Vertically
4. Scroll Horizontally
5. Zoom
6. Blur
0. Quit

Choice: 0

Goodbye!